Repository navigation
fix(tools): validate inner ELF machine and header size - #10733
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed head efc4ed1b7b9c9995e23fd8b657df962bebeb7329. The parser now rejects unsupported inner ELF machine values and non-64-byte ELF64 headers before using the program-header metadata. The new tests cover both direct parsing and CLI behavior, including preserving an existing output and leaving no new output on refusal. The reported Windows and Linux Python suites include baseline comparisons, and the official relinker, ASAN, conventions, intake and labels checks pass; the product Linux/Windows jobs are skipped under the repository workflow policy.
THEMANnt
left a comment
There was a problem hiding this comment.
Reviewed efc4ed1b7b9c against 2dc85609fc1f. No actionable findings in this focused review.
Source review
parse_elf now reads both complete 16-bit fields and refuses machines other than x86-64 (62) or header sizes other than 64, matching the relinker's checks. Rejection occurs before segment processing or output staging and uses the existing Refused diagnostic and exit status 2. Supported metadata continues through the unchanged output-layout path.
The new tests cover six unsupported machines, six invalid sizes, and eight real CLI cases. The CLI assertions verify unchanged input, preserved existing output or no newly created output, no temporary-file residue, and clean diagnostics. Fixtures are isolated, and existing assertions remain intact.
Validation
Controller-recorded tools/tests/test_unwrap_self.py execution on Windows with Python 3.11.9:
- Baseline: 47 passed, 4 skipped; 51 total.
- Pristine PR and candidate, each: 50 passed, 4 skipped; 54 total.
- Candidate tests against baseline code: 20 intended assertion failures across three methods, with no setup errors. The eight CLI subcases fail at status 0 versus expected 2; later preservation assertions pass on the fixed code.
Recorded whitespace and conventions checks succeeded. GitHub reports success for the four named relinker matrix jobs, relinker-asan, intake, conventions, labels and eligibility. windows, linux, register-context and write-watch were skipped.
Scope
Local evidence covers the Python tool on the recorded interpreter. Broader author-reported checks were not independently reproduced; full application behavior was not tested.
What
Refuse inner ELF metadata the relinker already rejects:
e_machinemust be x86-64 (62) ande_ehsizemust be the ELF64 header size (64). The unwrapper currently accepts other values, can replace a previous output and reports success even though the relinker refuses the emitted ELF.Validate both complete 16-bit fields before segment processing or output staging, with explicit received/expected values through the existing
Refusedpath. Supported inputs and output layout are unchanged. This is independent of #10580's ELF-version checks and #10586's temporary-file I/O change; neither is included or required.Tested
main:2dc85609fc1f70965ca88829560a73ad3c363493; headefc4ed1b7b9c9995e23fd8b657df962bebeb7329. Rebased from50757b01c6; intervening upstream changes affect only AGC code/docs, and both changed unwrapper files are identical after the rebase.f1d0d96114f2d8496aaf9fd465c32bb94809352e: 244/244 passed in 233.58 seconds (cmake --build build-relinker --parallel 4,ctest --test-dir build-relinker --output-on-failure --parallel 4). Toolchain: MinGW-w64 GCC 14.1 UCRT, Python 3.13.5,ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON. Focused full Python suites and compatibility checks are rerun after rebasing; no full-product/GPU build was run.python tools/tests/test_unwrap_self.py: Windows Python 3.13.5 54 run, 50 passed, 4 existing skips; Linux Python 3.11.0rc1 54 run, 53 passed, 1 Windows-only skip. All three new methods pass five repetitions on Windows Python 3.9.13 and on each Linux interpreter (3.10.12 and 3.11.0rc1).io.open, but this interpreter'sPath.openuses its cached accessor. fix(tools): open the unwrap_self temporary file through io.open #10586 addresses that separate issue; no skips, timeouts or unrelated tests are changed here.e_machine = 0ande_ehsize = 0, then the built relinker with--skip-sce-modulerefuses those emitted files with its architecture/header-size diagnostics. This fix refuses both before creating output. Both supported SELF magics still unwrap successfully with machine 62 and header size 64 intact.tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch fix/unwrap-elf-header-metadata --jobs 4reports no overlap with open pull requests. This scan used the identical patch before the AGC-only rebase; no unwrapper source/tests changed upstream. Conventions and whitespace checks pass. No title, full-product, GPU or local macOS testing.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)