Repository navigation
find_hash_lookup: refuse a --json that names the scanned image or a folder - #6749
evilclanker9000 wants to merge 3 commits into
Conversation
…older The report was written after the scan with no check on its path, so --json naming the .exe replaced the game image with the report. The guard runs before the image is read, and a folder is refused here too instead of failing at the write. (DeepSeek8)
…back A missing parent folder, an --out that names a folder or a full disk raised from the report write after the whole image had been scanned; the ranking had already been printed and the exit status was 1 with a stack trace. Name the path and exit 2, as the other tools' report writers do. (DeepSeek8)
Three synthetic-PE cases: --json naming the image itself (the image must be byte for byte unchanged and stdout empty, so the guard runs before the scan), --json naming a folder, and --json in a missing folder (one ERROR line, exit 2, no traceback). All three fail on upstream/main. (DeepSeek8)
|
Independently reviewed and tested Additional real-filesystem CLI checks on the suite's synthetic PE:
No blocking findings within this scope. The shared path guard catches the additional aliases, and the actual write failure is handled cleanly. This checks the tested refusal/write-error cases, not atomic replacement or power-loss durability of report output. CPU only, synthetic PE and temporary reports; no game executable or GPU used. AI-assisted review with Codex; suites, negative control and Win32-handle reproduction executed locally. |
|
Independent CPU review at Code inspection:
Checks run on Linux CPU:
Looks good to merge. |
|
Tested 30d8235 merged with main 14b2e44 on Linux/Python 3.12.16: pass Commands run (merged worktree,
Diff read: |
shayderrr
left a comment
There was a problem hiding this comment.
Summary
tools/find_hash_lookup.py inserts its script directory on sys.path for -I-mode sibling imports, refuses --json that aliases the scanned image or a folder, and wraps report writing in OSError handling with exit 2. Tests cover all three failure cases.
Why merge
Without these guards the tool could truncate its input image, fail on a directory path, or emit a raw traceback when its report folder is missing. The checks turn those into clear, safe errors.
Verdict: Approve
Summary
Why mergeWithout these guards the tool could truncate its input image, fail on a directory path, or emit a raw traceback when its report folder is missing. The checks turn those into clear, safe errors. Verdict: Approve |
|
Tested 30d8235 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass. Ran the test files this PR adds or changes, from a clean checkout of the PR head: AI-assisted (Claude Code). |
tools/find_hash_lookup.pywrites its--jsonreport after the scan with no check on thepath (the write was at the end of
main()). Two consequences:--jsonnaming the image it reads (--json game_scarlett_master.exe) replaced the gameexecutable with the JSON report: the tool opened the same file for writing after reading it,
so the PE was truncated by its own report.
--jsonnaming a folder, or a path in a folder that does not exist, raised a stack tracefrom the report write — after the ranking had been printed — and exited 1.
This refuses both before the image is read, with one
ERROR:line and exit 2, the wayrtti_scan.pyand the other tools guard their report path (tools/report_paths.py,same_report_path). A report path that cannot be written (read-only file, full disk) is nowone
ERROR: cannot write <path>: <reason>line and exit 2 instead of a traceback.Test
The three new cases build the same synthetic PE the test already used:
--json <the image>: exit 2, stdout empty (so the guard runs before the scan), and theimage is byte for byte unchanged;
--json <a folder>: exit 2, oneERROR:line, noTraceback;--json <tmp>/missing/report.json: exit 2, oneERROR: cannot write ...line, no reportand no
Traceback.Before the change, with the tool reverted and the tests kept:
With the change:
python -m compileall -qandpython -I tools/find_hash_lookup.py --helpare clean.No GPU needed.
Notes
--jsoncannot destroy the executable even when the scan itself would have failed.
--windowand--topstill take any integer (--top 0prints no candidates, a negative--windowscans a shorter tail). That is a separate argument check and I left it out ofthis PR to keep it one refusal.
main()only; the pending joaat change in find_hash_lookup: hash a name over the lower-cased Latin-1 bytes, as the other joaat copies do #6254 is injoaat()and does notoverlap.
AI-assisted.