fix(relinker): reject section header file ranges outside the input file #9168

Merged
slopgobblercobbler merged 1 commit from upstream-pr/9168 into main 2026-10-23 13:17:16 +00:00
slopgobblercobbler commented 2026-10-21 14:09:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-21T14:09:28Z.


What

Validate that ELF section headers with file contents (sh_type not SHT_NULL or SHT_NOBITS and non-zero sh_size) lie within the input file buffer in ElfReader::ReadSectionHeaders. Add SHT_NOBITS constant to ElfConstants.hpp and add comprehensive bounds coverage to ElfReaderBoundsTests.cpp (including past-EOF rejection, integer offset overflow, exact-EOF boundary, empty sections, and unbacked SHT_NOBITS sections).

Tested

Local C++ unit tests in ElfReaderBoundsTests on Windows (elf_reader_bounds_tests.exe), building via CMake + Ninja and verified via CTest. tools/check_conventions.py and tools/pr_overlap.py.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4952973099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9168). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-21T14:09:28Z. --- ### What Validate that ELF section headers with file contents (`sh_type` not `SHT_NULL` or `SHT_NOBITS` and non-zero `sh_size`) lie within the input file buffer in `ElfReader::ReadSectionHeaders`. Add `SHT_NOBITS` constant to `ElfConstants.hpp` and add comprehensive bounds coverage to `ElfReaderBoundsTests.cpp` (including past-EOF rejection, integer offset overflow, exact-EOF boundary, empty sections, and unbacked `SHT_NOBITS` sections). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Local C++ unit tests in `ElfReaderBoundsTests` on Windows (`elf_reader_bounds_tests.exe`), building via CMake + Ninja and verified via CTest. `tools/check_conventions.py` and `tools/pr_overlap.py`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-21 22:07:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:07:28Z.

Review: COMMENTED


Confirmed on macOS Apple Silicon, arm64 and x86-64 under Rosetta (your run was Windows only).

  • Machine: Apple M2 Max, macOS 27.2, AppleClang, relinker-only Release. Head 66b631498 on current main a6dcea9279 (merged clean).
  • Full relinker-only CTest: arm64 229/229; x86-64 under Rosetta (-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3, Python 3.9.6) 229/229.

Red/green on elf_reader_bounds: with the ReadSectionHeaders bounds check reverted to main (new ElfReaderBoundsTests kept), the test fails; with the fix it passes. So the added coverage (past-EOF rejection, offset overflow, exact-EOF boundary, empty sections, unbacked SHT_NOBITS) really protects the "section file range outside the input file" regression.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5606833962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9168#pullrequestreview-5606833962). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-21T22:07:28Z. **Review:** COMMENTED --- Confirmed on macOS Apple Silicon, arm64 and x86-64 under Rosetta (your run was Windows only). - Machine: Apple M2 Max, macOS 27.2, AppleClang, relinker-only Release. Head 66b631498 on current `main` a6dcea9279 (merged clean). - Full relinker-only CTest: arm64 **229/229**; x86-64 under Rosetta (`-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3`, Python 3.9.6) **229/229**. Red/green on `elf_reader_bounds`: with the `ReadSectionHeaders` bounds check reverted to `main` (new `ElfReaderBoundsTests` kept), the test fails; with the fix it passes. So the added coverage (past-EOF rejection, offset overflow, exact-EOF boundary, empty sections, unbacked `SHT_NOBITS`) really protects the "section file range outside the input file" regression. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9168
No description provided.