Repository navigation
pe_inspect: name the header a short file stops before, not a missing signature - #2557
Conversation
…signature A 4-byte truncated copy that starts with MZ was rejected as "no MZ header", but the signature is there: the file is just shorter than the 64-byte MS-DOS header that carries e_lfanew at 0x3c. The same class of wrong cause sat one check later, where a cut before or inside the PE header said "no PE signature" even when PE\0\0 was present and only the bytes after it were missing. The signature and the length are now checked apart, each reporting its real cause. Tested with the new ShortHeaderTest (hand-built bytes, parser and CLI paths): 4 of its 6 cases fail without the parser change; the suite runs 50 tests, all passing, 1 Windows-only skip. AI-assisted: written by Qwen (model qwen3.8-gx10-claude-compatible). Co-Authored-By: Qwen qwen3.8-gx10-claude-compatible <noreply@qwen.ai>
|
Tested I checked AI-assisted verification. |
|
Verified head e739047 on Linux (CachyOS), Python 3.14.10, CPU only, hand-written bytes only. Ran: Own probes through
The same probes on origin/main reproduce the before-column exactly. No issues found; only gap is that e_lfanew 0 is not in the new tests. |
New BUILD item, claimed here.
What was wrong
tools/pe_inspect.pychecked a signature and a length in one condition and reported both as the missing signature:MZ, shorter than 64 bytes (a truncated copy)no MZ headerfile is N bytes, shorter than the 64-byte MS-DOS headere_lfanewpoints at or past the end, or the file is cut inside the PE header (even right afterPE\0\0)no PE signaturefile is N bytes, too short to hold the PE header at 0x…MZat the start (including empty and 1-byte files)no MZ headerPE\0\0should beno PE signatureThe first two sent the reader looking for a wrong signature when bytes were missing. Nothing else in the parser changes; every case is still a
PeFormatErrorand exit 1 from the CLI.Overlap
#2456 (@Dom-in, run-time load candidates) touches the same two files elsewhere;
git merge-treeof the two branches is clean.Tested
Linux 6.8, Python 3.12.3, CPU only; no GPU, no game files.
python -I tests/test_pe_inspect.py: 50 tests: 49 pass, 1 Windows-only skip. The newShortHeaderTest(6 tests, hand-written bytes) checks bothPeImageand the CLI.tools/pe_inspect.pyfrommain, 4 of the 6 fail (the other 2 assert the unchanged messages).tests/test_pe_shader_containers.pyandtests/test_bad_input_errors.pystill pass.AI-assisted: written by Qwen (model qwen3.8-gx10-claude-compatible), reviewed and re-run with Claude Code.