test(relinker): add bounds and termination tests for dynamic tags and segment reading #12009

Closed
slopgobblercobbler wants to merge 1 commit from upstream-pr/12009 into main
slopgobblercobbler commented 2026-10-27 17:01:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-27T17:01:07Z.


What

Adds unit test coverage in core/relinker/relinker/tests/ElfReaderBoundsTests.cpp for bounds and termination validation in ElfReader:

  • ElfReader::ReadDynamicTags: tests that a dynamic header with offset/size extending past file bounds or overflowing throws RelinkerException("Dynamic segment out of bounds", dynamicHeader.Offset).
  • ElfReader::ReadDynamicTags: tests that a dynamic segment lacking a terminating DT_NULL tag throws RelinkerException("Unterminated dynamic segment", dynamicHeader.Offset), and verifies correct tag extraction when terminated.
  • ElfReader::ReadSegment: tests that a segment header with offset/size extending past file bounds throws RelinkerException("Segment offset out of bounds", header.Offset), and verifies correct byte retrieval for valid segments.

Tested

  • Unit test elf_reader_bounds (all 34 cases passed including dynamic tag and segment bounds tests).
  • python tools/check_conventions.py --base upstream/main --head HEAD passed with 0 findings.
  • Windows 11 verification courtesy of @JJenkx: Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7, Ninja Release build, all 376 relinker CTests passed across 3 runs with head d36fb789b1 merged onto 86fb985abb.
  • macOS arm64 mutation analysis courtesy of @rooklz: 8/8 mutation probes in ElfReader.cpp killed; full ctest passed 361/361.
  • Windows verification courtesy of @THEMANnt: Windows / GCC 15.2 Release build, elf_reader_bounds passed 1/1.

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:5037943401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12009). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-27T17:01:07Z. --- ### What Adds unit test coverage in `core/relinker/relinker/tests/ElfReaderBoundsTests.cpp` for bounds and termination validation in `ElfReader`: - `ElfReader::ReadDynamicTags`: tests that a dynamic header with offset/size extending past file bounds or overflowing throws `RelinkerException("Dynamic segment out of bounds", dynamicHeader.Offset)`. - `ElfReader::ReadDynamicTags`: tests that a dynamic segment lacking a terminating `DT_NULL` tag throws `RelinkerException("Unterminated dynamic segment", dynamicHeader.Offset)`, and verifies correct tag extraction when terminated. - `ElfReader::ReadSegment`: tests that a segment header with offset/size extending past file bounds throws `RelinkerException("Segment offset out of bounds", header.Offset)`, and verifies correct byte retrieval for valid segments. ### Tested - Unit test `elf_reader_bounds` (all 34 cases passed including dynamic tag and segment bounds tests). - `python tools/check_conventions.py --base upstream/main --head HEAD` passed with 0 findings. - Windows 11 verification courtesy of @JJenkx: Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7, Ninja Release build, all 376 relinker CTests passed across 3 runs with head `d36fb789b1` merged onto `86fb985abb`. - macOS arm64 mutation analysis courtesy of @rooklz: 8/8 mutation probes in `ElfReader.cpp` killed; full ctest passed 361/361. - Windows verification courtesy of @THEMANnt: Windows / GCC 15.2 Release build, `elf_reader_bounds` passed 1/1. ### Checklist - [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
rooklz commented 2026-10-28 02:20:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T02:20:59Z.

Review: APPROVED


Reviewed on macOS (arm64, relinker-only Release build) @ d36fb789b1. The PR is test-only, so the question is whether the new cases catch regressions in the guards they target. I checked that with mutation probes on ElfReader.cpp: one mutant at a time, rebuilding only elf_reader_bounds_tests.

Mutant in ElfReader.cpp main test file this PR
M1 ReadDynamicTags range check removed passes fails (dynamic segment out of bounds)
M2 dynamic check as naive Offset + FileSize > size (wraps) passes fails
M3 unterminated → return tags passes fails (unterminated dynamic segment)
M4 loop condition >= 16 → >= 8 (partial entry read) passes fails
M5 DT_NULL not recognised as terminator passes fails
M6 ReadSegment range check removed passes fails (segment offset out of bounds)
M7 segment check as naive wrapping sum passes fails
M8 segment check offset-only (size ignored) passes fails

The file on main catches 0 of 8 mutants and this PR catches 8 of 8. So the coverage is new, and the max-15 / 32 overflow rows are what catch the wrapping-sum mutants (M2/M7). The source was restored afterwards and the tree is clean.

  • elf_reader_bounds passes; full ctest -j 8 passes 361/361
  • check_conventions.py --base upstream/main: all passed
  • pr_overlap.py: no overlap with open pull requests
  • The parent 737f17291a is an ancestor of main. Neither ElfReader.cpp nor this test file has changed on main since then (0 lines), and git merge-tree against current main (cccdaa2734) is clean.

LGTM.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5676982908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12009#pullrequestreview-5676982908). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T02:20:59Z. **Review:** APPROVED --- Reviewed on macOS (arm64, relinker-only Release build) @ d36fb789b1. The PR is test-only, so the question is whether the new cases catch regressions in the guards they target. I checked that with mutation probes on `ElfReader.cpp`: one mutant at a time, rebuilding only `elf_reader_bounds_tests`. | Mutant in `ElfReader.cpp` | main test file | this PR | |---|---|---| | M1 `ReadDynamicTags` range check removed | passes | **fails** (dynamic segment out of bounds) | | M2 dynamic check as naive `Offset + FileSize > size` (wraps) | passes | **fails** | | M3 unterminated → `return tags` | passes | **fails** (unterminated dynamic segment) | | M4 loop condition `>= 16` → `>= 8` (partial entry read) | passes | **fails** | | M5 DT_NULL not recognised as terminator | passes | **fails** | | M6 `ReadSegment` range check removed | passes | **fails** (segment offset out of bounds) | | M7 segment check as naive wrapping sum | passes | **fails** | | M8 segment check offset-only (size ignored) | passes | **fails** | The file on main catches 0 of 8 mutants and this PR catches 8 of 8. So the coverage is new, and the `max-15 / 32` overflow rows are what catch the wrapping-sum mutants (M2/M7). The source was restored afterwards and the tree is clean. - `elf_reader_bounds` passes; full `ctest -j 8` passes 361/361 - `check_conventions.py --base upstream/main`: all passed - `pr_overlap.py`: no overlap with open pull requests - The parent `737f17291a` is an ancestor of main. Neither `ElfReader.cpp` nor this test file has changed on main since then (0 lines), and `git merge-tree` against current main (cccdaa2734) is clean. LGTM. AI-assisted: yes
THEMANnt commented 2026-10-28 05:01:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T05:01:11Z.

Review: APPROVED


Reviewed d36fb789b1b918b05d329bd5641008ac58f2b4f6 — approve. The added reader cases exercise out-of-bounds/overflowing dynamic and data segments, missing DT_NULL termination and valid reads.

Fresh Windows/GCC 15.2 Release build: elf_reader_bounds passes 1/1 on both exact head and author base. Reviewed the three new case groups and their exception-message assertions. This is new coverage for existing checks; the production reader is unchanged and a failing old-production control is not expected. The inspected hosted Windows job merged this head and passed the same registered test. No full product or game execution is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677989882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12009#pullrequestreview-5677989882). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T05:01:11Z. **Review:** APPROVED --- Reviewed `d36fb789b1b918b05d329bd5641008ac58f2b4f6` — approve. The added reader cases exercise out-of-bounds/overflowing dynamic and data segments, missing DT_NULL termination and valid reads. Fresh Windows/GCC 15.2 Release build: elf_reader_bounds passes 1/1 on both exact head and author base. Reviewed the three new case groups and their exception-message assertions. This is new coverage for existing checks; the production reader is unchanged and a failing old-production control is not expected. The inspected hosted Windows job merged this head and passed the same registered test. No full product or game execution is claimed.

Pull request closed

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!12009
No description provided.