diff --git a/CHANGELOG.md b/CHANGELOG.md index db5fe728..12795600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - loader: handle struct.error from dnfile and show clear CorruptFile message @devs6186 #2442 - address: fix TypeError when sorting locations containing mixed address types @devs6186 #2195 - loader: skip PE files with unrealistically large section virtual sizes to prevent resource exhaustion @devs6186 #1989 +- engine/render: fix unbounded range sentinel precedence so `count(...): N or more` uses explicit `((1 << 64) - 1)` @blenbot #2936 ### capa Explorer Web - webui: fix 404 for "View rule in capa-rules" by using encodeURIComponent for rule name in URL @devs6186 #2482 diff --git a/capa/engine.py b/capa/engine.py index 225c3d2e..fc1919fa 100644 --- a/capa/engine.py +++ b/capa/engine.py @@ -227,7 +227,7 @@ class Range(Statement): super().__init__(description=description) self.child = child self.min = min if min is not None else 0 - self.max = max if max is not None else (1 << 64 - 1) + self.max = max if max is not None else ((1 << 64) - 1) def evaluate(self, features: FeatureSet, short_circuit=True): capa.perf.counters["evaluate.feature"] += 1 @@ -240,7 +240,7 @@ class Range(Statement): return Result(self.min <= count <= self.max, self, [], locations=features.get(self.child)) def __str__(self): - if self.max == (1 << 64 - 1): + if self.max == ((1 << 64) - 1): return f"range({str(self.child)}, min={self.min}, max=infinity)" else: return f"range({str(self.child)}, min={self.min}, max={self.max})" diff --git a/capa/ida/plugin/model.py b/capa/ida/plugin/model.py index 046dc1ea..c5e510ba 100644 --- a/capa/ida/plugin/model.py +++ b/capa/ida/plugin/model.py @@ -403,7 +403,7 @@ class CapaExplorerDataModel(QtCore.QAbstractItemModel): display += f"{statement.min}" elif statement.min == 0: display += f"{statement.max} or fewer" - elif statement.max == (1 << 64 - 1): + elif statement.max == ((1 << 64) - 1): display += f"{statement.min} or more" else: display += f"between {statement.min} and {statement.max}" diff --git a/capa/render/vverbose.py b/capa/render/vverbose.py index e905f8c0..fe378a80 100644 --- a/capa/render/vverbose.py +++ b/capa/render/vverbose.py @@ -172,7 +172,7 @@ def render_statement(console: Console, layout: rd.Layout, match: rd.Match, state console.write(f"{statement.min}") elif statement.min == 0: console.write(f"{statement.max} or fewer") - elif statement.max == (1 << 64 - 1): + elif statement.max == ((1 << 64) - 1): console.write(f"{statement.min} or more") else: console.write(f"between {statement.min} and {statement.max}")