Skip to content

Commit d3704b9

Browse files
author
Han Wang
committed
test(lmp): reject negative array counts in expected_ref parser
CodeRabbit (review #4211393623) noted that a negative `count` in a sidecar array header (e.g. `expected_e -3`) would pass the existing length check (`i + n > len(lines)` is false for n<0), then `range(-3)` yields no values, and `i += -3` rewinds the read position — at best re-parsing earlier lines, at worst looping forever on a long file. Add an explicit `n < 0` guard with a clear message naming both the array and the file.
1 parent a444251 commit d3704b9

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

source/lmp/tests/expected_ref.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def read_expected_ref(path):
3434
)
3535
key, count = parts
3636
n = int(count)
37+
if n < 0:
38+
raise ValueError(f"array '{key}' has negative count {n} in {path}")
3739
if i + n > len(lines):
3840
raise ValueError(
3941
f"array '{key}' expects {n} values, but only {len(lines) - i} remain in {path}"

0 commit comments

Comments
 (0)