find_hash_lookup: clamp raw section sizes and validate window and top parameters (OLD-9792) #1268

Merged
leonida/mandy
wetw0rks-c0ding merged 2 commits from feat/find-hash-lookup-bounds into main 2026-11-28 19:36:59 +00:00

Pull request successfully merged and closed

wetw0rks-c0ding commented 2026-11-24 21:05:48 +00:00

Claimed in the coordination issue as: OLD-9792

What and why

tools/find_hash_lookup.py trusted raw section sizes and unchecked window/top parameters, so malformed inputs could drive an out-of-range read. It now clamps the sizes and validates the parameters, with regression tests.

Tested

  • python3 -I tests/test_find_hash_lookup.py -> Ran 12 tests, OK (exit 0)
  • python -I scripts/check_no_game_data.py tools/find_hash_lookup.py tests/test_find_hash_lookup.py -> clean (exit 0)
  • Environment: Linux (CachyOS), CPU-only tests, no GPU required

AI-assisted: Yes. This work was done with OpenCode agents.

Claimed in the coordination issue as: OLD-9792 ### What and why `tools/find_hash_lookup.py` trusted raw section sizes and unchecked window/top parameters, so malformed inputs could drive an out-of-range read. It now clamps the sizes and validates the parameters, with regression tests. ### Tested - `python3 -I tests/test_find_hash_lookup.py` -> Ran 12 tests, OK (exit 0) - `python -I scripts/check_no_game_data.py tools/find_hash_lookup.py tests/test_find_hash_lookup.py` -> clean (exit 0) - Environment: Linux (CachyOS), CPU-only tests, no GPU required AI-assisted: Yes. This work was done with OpenCode agents.
nicoco23 commented 2026-11-24 22:06:14 +00:00

Reviewed the diff and ran the tests: python -I tests/test_find_hash_lookup.py on Windows 11, Python 3.12, 12 tests, OK.

The clamp in sections() reads right to me: len(data) - raw floored at 0, then min(vsize or rsize, rsize, file_avail), so a raw offset past EOF gives size 0 and the section is not scanned. Validating --window (>= 0) and --top (>= 1) before parsing is the right order.

Nits, none blocking:

  • test_truncated_pe_does_not_crash passes whether rank() returns, raises ValueError or raises struct.error, and asserts nothing about the result. A test that calls sections() on the truncated data and checks each size is <= len(data) - raw would pin the clamp itself. There is no case for raw past EOF or for vsize == 0.
  • The ValueError messages name --window and --top, but rank() takes window and top. Naming the parameters would read better for library callers.

NOT AI-assisted review

Reviewed the diff and ran the tests: `python -I tests/test_find_hash_lookup.py` on Windows 11, Python 3.12, 12 tests, OK. The clamp in sections() reads right to me: len(data) - raw floored at 0, then min(vsize or rsize, rsize, file_avail), so a raw offset past EOF gives size 0 and the section is not scanned. Validating --window (>= 0) and --top (>= 1) before parsing is the right order. Nits, none blocking: - test_truncated_pe_does_not_crash passes whether rank() returns, raises ValueError or raises struct.error, and asserts nothing about the result. A test that calls sections() on the truncated data and checks each size is <= len(data) - raw would pin the clamp itself. There is no case for raw past EOF or for vsize == 0. - The ValueError messages name --window and --top, but rank() takes window and top. Naming the parameters would read better for library callers. NOT AI-assisted review
wavehs commented 2026-11-26 18:47:55 +00:00

This is the same change as #696 (abnalstlll-byte, opened 2026-11-24 12:17, ~8h48m earlier): git diff of the two PR diffs is byte-identical (only the blob hashes differ), both touch tools/find_hash_lookup.py + tests/test_find_hash_lookup.py, and both claim OLD-9792. I applied #696 to main f107ae044: it applies cleanly and python3 -I tests/test_find_hash_lookup.py is OK.

No defect in this PR — just two copies of one reland. My vote is #696 because it is earlier and says it restores the original author explicitly; if this one is preferred for some reason, #696 should be the one closed. Either way only one should merge.

AI-assisted (review/verification only).

This is the same change as **#696** (abnalstlll-byte, opened 2026-11-24 12:17, ~8h48m earlier): `git diff` of the two PR diffs is byte-identical (only the blob hashes differ), both touch `tools/find_hash_lookup.py` + `tests/test_find_hash_lookup.py`, and both claim OLD-9792. I applied #696 to `main` `f107ae044`: it applies cleanly and `python3 -I tests/test_find_hash_lookup.py` is `OK`. No defect in this PR — just two copies of one reland. My vote is #696 because it is earlier and says it restores the original author explicitly; if this one is preferred for some reason, #696 should be the one closed. Either way only one should merge. AI-assisted (review/verification only).
MoonEyes commented 2026-11-28 19:36:55 +00:00

Red/green: tests/test_find_hash_lookup.py fails 7 assertions on main (raw section sizes not clamped to the file, bad --window/--top accepted) and passes with the PR (cloud run on main 7daa4a4, re-run on Windows against main 8b318bd).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: tests/test_find_hash_lookup.py fails 7 assertions on main (raw section sizes not clamped to the file, bad --window/--top accepted) and passes with the PR (cloud run on main 7daa4a4, re-run on Windows against main 8b318bd). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.