fix(tools): bound PE audit directories by optional header size #7460
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7460"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Lyrilika on 2026-10-18T08:27:37Z.
What
import_audit.pychecks that the optional header contains an export-directory slot, but does not check whether the declared data-directory count fits the header. A PE header with space for 16 directories and a count of 17 is accepted; the audit can succeed and replace an existing JSON report using malformed input. With a shorter header, the import reader can interpret section-table bytes as an import directory.Validate the directory count against the remaining optional-header bytes in the shared PE header parser. Invalid counts now raise
AuditErrorbefore either reader processes directories, so the CLI returns 2 and preserves the previous report. Variable-length PE32 and PE32+ headers remain supported. This follows Microsoft's optional-header bounds requirements.Tested
Arch Linux x86-64, Python 3.14.8. Tested on
mainate5c2b3c325e4. No game/homebrew execution, Windows runtime run or GPU testing.python3 tools/tests/test_import_audit.py: 109 tests run, 108 passed, one Windows-only test skipped. Covers PE32/PE32+, truncated directory arrays, a partial trailing slot, count overflow beyond a full header, maximum 32-bit count, valid shorter headers, CLI exit status and preservation of an existing report.ctest --test-dir build-relinker --output-on-failure -j4: all 194 tests passed.python3 tools/check_conventions.py --base origin/mainandgit diff --check: passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:11:38Z.
Linux data point for
70986ca71f(WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; Python 3.12.3), this head merged ontomain5d10ea9ea(clean merge),python3 -I tools/tests/test_import_audit.py:test_import_audit.pyon top ofmainwithout the PR's source change): FAILED (18 failures).Not tested: macOS, Windows (Windows data from another run is not part of this comment).
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:36:54Z.
Windows data point for
70986ca71f: Windows 10 19045, Python 3.12.10, WinLibs GCC 15.2.0 and Ninja on PATH, this head merged ontomain05f9995704(clean merge),python -I tools/tests/test_import_audit.py:test_import_audit.pyon top ofmainwithout the PR's source change): FAILED (18 failures).Not tested: Linux/macOS in this comment.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-21T05:32:37Z.
Review: APPROVED
Verified on Windows 11, Python 3.14:
python tools/tests/test_import_audit.pyon the PR head: 109 tests, OK (3 skipped: two POSIX permission tests, one symlink test that needs a privilege I don't have).tools/import_audit.pyfrom main, the new tests fail with 18 failures: 16 subtests intest_pe_data_directories_must_fit_inside_optional_headerand 2 intest_invalid_pe_directory_count_preserves_audit_report.test_pe_variable_optional_headers_keep_declared_directoriespasses on both versions, as expected.(optional_size - directory) // 8uses the 96/112 data-directory offsets for PE32/PE32+, rejects a partial trailing slot and accepts exact fits (dir+16 with count 2, dir+128 with count 16). It sits in the sharedpe_headers, so both readers are covered.kernel32.dllandntdll.dllstill parse exports and imports.git merge-treeagainst current main is clean. With the mergedtools/tree,test_import_audit.pyruns 125 tests, OK (3 skipped).python tools/check_conventions.py --base main: passed.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-21T18:57:45Z.
Review: APPROVED
Reviewed at
70986ca71fon Windows 11, Python 3.11.9; cherry-picked cleanly onto local mainf894ba69d300. No actionable findings.The three local skips are POSIX permission checks and a symlink-privilege check. No Linux/macOS run, native rebuild, game or GPU validation was performed for this Python parser change.
AI-assisted: yes (Codex); all stated local checks were run on this machine.