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

Open
github-bot wants to merge 1 commit from github-bot/gh-1268 into main AGit
Owner

@⁠wetw0rks-c0ding on GitHub · 2026-11-24 21:05 UTC · original
wetw0rks-c0ding:feat/find-hash-lookup-bounds → main · +86 −1 · 2 files · 1 commits · open

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.

**@⁠wetw0rks-c0ding** on GitHub · 2026-11-24 21:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1268) `wetw0rks-c0ding:feat/find-hash-lookup-bounds` → `main` · +86 −1 · 2 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:45:05 +00:00
Author
Owner

@⁠nicoco23 on GitHub · 2026-11-24 22:06 UTC · original

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

**@⁠nicoco23** on GitHub · 2026-11-24 22:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1268#issuecomment-7145807236) 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
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:47 UTC · original

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).

**@⁠wavehs** on GitHub · 2026-11-26 18:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1268#issuecomment-7200862732) 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 pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1268/head:github-bot/gh-1268'
git switch 'github-bot/gh-1268'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1268'
git switch 'github-bot/gh-1268'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1268'
git switch 'github-bot/gh-1268'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1268'
git switch 'main'
git merge --squash 'github-bot/gh-1268'
git switch 'main'
git merge --ff-only 'github-bot/gh-1268'
git switch 'main'
git merge 'github-bot/gh-1268'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.