Skip to content

find_hash_lookup: refuse an unusable --json up front; a failed write is one error line - #6202

Open
Koro4e wants to merge 2 commits into
ItsNotRexed:mainfrom
Koro4e:find-hash-json
Open

Koro4e wants to merge 2 commits into
ItsNotRexed:mainfrom
Koro4e:find-hash-json

Conversation

@Koro4e

@Koro4e Koro4e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Finding + claim in the coordination issue: tools/find_hash_lookup.py:140 wrote its --json report with no guard, so a --json naming a folder ended in IsADirectoryError after the whole scan ran.

The folder is refused right after parse_args, before the exe is even opened, and the write itself is wrapped so a failure prints one ERROR: cannot write ... line and exits 2.

Tested

  • python -m pytest tests/test_find_hash_lookup.py -q: all pass, including the new test_a_json_that_names_a_folder_is_refused_before_the_scan (exit 2, one line, nothing printed before the refusal).
  • Negative control: with main's tool the new test fails (the scan output was printed and then the traceback happened).

Two commits: the tool, then the test. Windows 11, Python 3.12.10, CPU only. No game files. AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator changes.)

… failed write one error line (finding in the coordination issue, claim 7102450817)
@AsgerCode

Copy link
Copy Markdown

Tested 09cc69b on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I tests/test_find_hash_lookup.py: 5 tests, OK. tests/test_first_look_shim_report.py: 1 test, OK on the PR head.
  • Negative control (merge base's tools/find_hash_lookup.py): the new test fails (AssertionError: 1 != 2, the scan output comes before the traceback).
  • A second control: I kept the new isdir check and removed only the new try/except OSError around the write. All 5 tests still pass, so no test covers the "a failed write is one error line" half.
  • Merge with main: clean with f25ba44 and with 8575d36. test_find_hash_lookup.py 5 OK on both. test_first_look_shim_report.py fails on both merged trees, and on main alone too (ModuleNotFoundError: No module named 'report_paths' from gdk_runtime_calls.py), so this PR does not cause it.

By hand, find_hash_lookup.py image.exe --json <X> with the test's synthetic image():

--json merge base this PR
an existing folder (also by its 8.3 name, and with a trailing \) rc 1, traceback after the scan rc 2, one line, no scan output
blocker\r.json (blocker is a file) rc 1, traceback rc 2 after the scan, cannot write ...: No such file or directory
parent folder missing rc 1, traceback rc 2 after the scan, same message
a read-only file rc 1, traceback rc 2, Permission denied
bad<name.json rc 1, traceback rc 2, Invalid argument
the scanned image.exe itself rc 0, image.exe replaced by the JSON rc 0, image.exe replaced by the JSON

Points, none blocking:

  1. The title says "refuse an unusable --json up front", but only a folder is refused before the scan. --json that names the input exe still gets rc 0 and overwrites the input with the report. The overlapping PRs below refuse that case with report_paths.same_report_path.
  2. Add a test for the write guard, for example --json <file>\r.json, and assert rc 2 and one stderr line.

Overlap: these open PRs change the same --json handling in main(), and each one conflicts with this PR in git merge-tree:

#5353 and #5532 already do everything that this PR does, and they also refuse the input alias. Only one of these is needed.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants