Skip to content

fix(tools): validate inner ELF machine and header size - #10733

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Bram910:fix/unwrap-elf-header-metadata
Oct 26, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Bram910:fix/unwrap-elf-header-metadata

Conversation

@Bram910

@Bram910 Bram910 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

What

Refuse inner ELF metadata the relinker already rejects: e_machine must be x86-64 (62) and e_ehsize must 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 Refused path. 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

  • Final base main: 2dc85609fc1f70965ca88829560a73ad3c363493; head efc4ed1b7b9c9995e23fd8b657df962bebeb7329. Rebased from 50757b01c6; intervening upstream changes affect only AGC code/docs, and both changed unwrapper files are identical after the rebase.
  • Full Windows x64 Ninja Release relinker-only build and CTest on pre-rebase head 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.
  • Red/green on Windows Python 3.9.13 and 3.13.5 and Linux Python 3.10.12 and 3.11.0rc1: unchanged main fails 20 rejection subcases, without setup errors. With the fix all three new methods pass. Coverage includes six unsupported machines, six invalid sizes, full-width/byte-swapped values, and eight real CLI cases preserving existing outputs or leaving no output/temp files, with unchanged source bytes and no traceback/partial stdout.
  • Full 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).
  • Default Linux Python 3.10.12 full suite is not clean: four pre-existing failed assertions in three I/O failure-injection methods, plus the Windows-only skip. Those same four assertions reproduce with both unchanged main and this branch. They patch io.open, but this interpreter's Path.open uses 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.
  • Actual relinker control on Windows: main's unwrapper reports success for e_machine = 0 and e_ehsize = 0, then the built relinker with --skip-sce-module refuses 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.
  • Compatibility: both merge orders with fix(tools): reject unsupported inner ELF versions #10580 and fix(tools): open the unwrap_self temporary file through io.open #10586 are clean and produce the same respective tree. Execute the merged production module and combined full tests, with subprocess CLI tests using a saved merged tool: fix(tools): reject unsupported inner ELF versions #10580 57 run, 53 passed, 4 existing skips; fix(tools): open the unwrap_self temporary file through io.open #10586 54 run, 50 passed, 4 existing skips on Windows. Neither is a dependency.
  • tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch fix/unwrap-elf-header-metadata --jobs 4 reports 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean oneandonlydean self-assigned this Oct 25, 2026
@oneandonlydean
oneandonlydean merged commit da1d222 into boykopovar:main Oct 26, 2026
13 checks passed
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.

4 participants