fix(range): correct unbounded max sentinel precedence

Signed-off-by: blenbot <harshitiszz23@gmail.com>
This commit is contained in:
blenbot
2026-03-17 16:43:11 +05:30
committed by Willi Ballenthin
parent 30d9989538
commit 7090aa9c37
4 changed files with 5 additions and 4 deletions
+1
View File
@@ -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
+2 -2
View File
@@ -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})"
+1 -1
View File
@@ -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}"
+1 -1
View File
@@ -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}")