test(relinker): cover Sony segment bounds and overflow handling #14121

Merged
slopgobblercobbler merged 1 commit from upstream-pr/14121 into main 2026-11-21 19:56:20 +00:00
slopgobblercobbler commented 2026-10-31 19:43:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:43:42Z.


What

Expands boundary and overflow test coverage in core/relinker/relinker/tests/ElfReaderBoundsTests.cpp for Sony ELF segment types (PT_SCE_DYNLIBDATA, PT_SCE_RELA, PT_SCE_LIBVERSION):

  • Adds SonySegmentFixture and RejectSegment test helpers to construct and validate ELF images carrying Sony segment types.
  • Adds test cases covering:
    • Header parsing and segment data reading for all three Sony segment types.
    • Invalid and boundary virtual addresses (zero, immediate bounds of PT_LOAD, disjoint ranges, and upper 64-bit boundaries) confirming rejection via RelinkerException without segfaulting.
    • Valid unaligned file offsets within file bounds and ending at EOF.
    • Unaligned file offset overflows exceeding buffer bounds and 64-bit integers triggering proper bounds exceptions.
    • Segment table bounds overflows (table truncation mid-entry, overflowing table offsets, and large table entry counts).
    • Unaligned segment table offsets and truncated unaligned tables using std::memmove for overlapping ranges.
    • Empty Sony segment boundary conditions at EOF and beyond EOF.

Tested

  • Unit test suite elf_reader_bounds_tests (ctest --test-dir build -R elf_reader_bounds -V): all test cases passed (100% pass rate).
  • Negative control / red-to-green mutation verification:
    • Relaxing _rangeFits to unconditionally return true triggers expected failures in unaligned offset overflow, segment table bounds overflow, unaligned table offset, and empty segment bounds tests.
    • Relaxing TranslateVirtualAddress to match non-PT_LOAD segments triggers expected failure in Sony segment invalid virtual addresses.
    • Restoring clean code restores 100% green pass rate across tests.
  • python tools/check_conventions.py --base upstream/main --head HEAD: passed with 0 findings.
  • git diff --check upstream/main...HEAD: clean (exit 0).

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:5100936309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14121). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-31T19:43:42Z. --- ### What Expands boundary and overflow test coverage in `core/relinker/relinker/tests/ElfReaderBoundsTests.cpp` for Sony ELF segment types (`PT_SCE_DYNLIBDATA`, `PT_SCE_RELA`, `PT_SCE_LIBVERSION`): - Adds `SonySegmentFixture` and `RejectSegment` test helpers to construct and validate ELF images carrying Sony segment types. - Adds test cases covering: - Header parsing and segment data reading for all three Sony segment types. - Invalid and boundary virtual addresses (zero, immediate bounds of `PT_LOAD`, disjoint ranges, and upper 64-bit boundaries) confirming rejection via `RelinkerException` without segfaulting. - Valid unaligned file offsets within file bounds and ending at EOF. - Unaligned file offset overflows exceeding buffer bounds and 64-bit integers triggering proper bounds exceptions. - Segment table bounds overflows (table truncation mid-entry, overflowing table offsets, and large table entry counts). - Unaligned segment table offsets and truncated unaligned tables using `std::memmove` for overlapping ranges. - Empty Sony segment boundary conditions at EOF and beyond EOF. ### Tested - Unit test suite `elf_reader_bounds_tests` (`ctest --test-dir build -R elf_reader_bounds -V`): all test cases passed (100% pass rate). - Negative control / red-to-green mutation verification: - Relaxing `_rangeFits` to unconditionally return `true` triggers expected failures in unaligned offset overflow, segment table bounds overflow, unaligned table offset, and empty segment bounds tests. - Relaxing `TranslateVirtualAddress` to match non-`PT_LOAD` segments triggers expected failure in `Sony segment invalid virtual addresses`. - Restoring clean code restores 100% green pass rate across tests. - `python tools/check_conventions.py --base upstream/main --head HEAD`: passed with 0 findings. - `git diff --check upstream/main...HEAD`: clean (exit 0). ### 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
MarcZX10 commented 2026-10-31 20:22:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T20:22:03Z.

Review: APPROVED


Reviewed — looks good

The updated tests now use std::memmove for the overlapping table fixture and the repository’s PT_SCE_DYNLIBDATA name; the relinker CI matrix and ASan pass on this head.

What I ran

Reviewed head fc04d8e9c3b4648498971d68b9a3d50702c6a257 against base 500d37a747c2b958e8696aa16213a0ee78d47505. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. I did not build or run CTest locally.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14121
python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
git diff --check 500d37a747c2b958e8696aa16213a0ee78d47505...fc04d8e9c3b4648498971d68b9a3d50702c6a257
git grep -n 'ElfReaderBoundsTests.cpp\|elf_reader_bounds_tests' fc04d8e9c3b4648498971d68b9a3d50702c6a257 -- core/relinker/CMakeLists.txt

Results

Check Result
Diff check, conventions/template, dependency preview Passed; preview against current base was clean
Test registration Confirmed in core/relinker/CMakeLists.txt and CTest (elf_reader_bounds)
Test-quality heuristic One possible-unregistered warning; false positive, because the helper does not inspect core/relinker/CMakeLists.txt; registration verified there
Automated precheck Its isolated checkout lacked the workspace-local heuristic script; I reran the helper directly against the exact head. Other precheck checks passed.
Hosted relinker CI Ubuntu, Windows, macOS arm64, macOS x86_64, and ASan jobs passed on this head. Linux/Windows product jobs and other specialized jobs were skipped.
Test run reported by author PR description reports 46/46 elf_reader_bounds_tests cases passed; I did not independently reproduce this local run.
Raw output from local checks
All conventions checks passed.

/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14121-fc04d8e9c3b4/head-fc04d8e9c3b4-219c33d5/tools/pr_test_quality.py': [Errno 2] No such file or directory

fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:264:    add_test_executable(elf_reader_bounds_tests
fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:265:        ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/ElfReaderBoundsTests.cpp
fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:267:    target_include_directories(elf_reader_bounds_tests PRIVATE
fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:271:    add_test(NAME elf_reader_bounds COMMAND elf_reader_bounds_tests)

{
  "findings": [
    {
      "path": "core/relinker/relinker/tests/ElfReaderBoundsTests.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

Negative control

Assertion Mutation reported by author Result
Bounds tests reject overflowing segment and table ranges, and reject Sony segments as virtual-address mappings Relax _rangeFits; separately allow TranslateVirtualAddress to match non-PT_LOAD segments PR description reports the corresponding tests failed under each mutation and all 46 passed after restoring the code; I did not rerun these mutations.

Findings

Blocking: None found.

Non-blocking: The test-quality warning is a confirmed false positive; the CMake file registers the test executable and the elf_reader_bounds CTest.

Sources

Not verified

I did not independently rerun the author’s 46-case CTest command or mutation controls. Hosted relinker and ASan jobs passed; Linux/Windows product jobs were skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724772987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14121#pullrequestreview-5724772987). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T20:22:03Z. **Review:** APPROVED --- # Reviewed — looks good The updated tests now use `std::memmove` for the overlapping table fixture and the repository’s `PT_SCE_DYNLIBDATA` name; the relinker CI matrix and ASan pass on this head. ## What I ran Reviewed head `fc04d8e9c3b4648498971d68b9a3d50702c6a257` against base `500d37a747c2b958e8696aa16213a0ee78d47505`. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. I did not build or run CTest locally. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14121 python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/relinker/relinker/tests/ElfReaderBoundsTests.cpp git diff --check 500d37a747c2b958e8696aa16213a0ee78d47505...fc04d8e9c3b4648498971d68b9a3d50702c6a257 git grep -n 'ElfReaderBoundsTests.cpp\|elf_reader_bounds_tests' fc04d8e9c3b4648498971d68b9a3d50702c6a257 -- core/relinker/CMakeLists.txt ``` ## Results | Check | Result | |---|---| | Diff check, conventions/template, dependency preview | Passed; preview against current base was clean | | Test registration | Confirmed in `core/relinker/CMakeLists.txt` and CTest (`elf_reader_bounds`) | | Test-quality heuristic | One possible-unregistered warning; false positive, because the helper does not inspect `core/relinker/CMakeLists.txt`; registration verified there | | Automated precheck | Its isolated checkout lacked the workspace-local heuristic script; I reran the helper directly against the exact head. Other precheck checks passed. | | Hosted relinker CI | Ubuntu, Windows, macOS arm64, macOS x86_64, and ASan jobs passed on this head. Linux/Windows product jobs and other specialized jobs were skipped. | | Test run reported by author | PR description reports 46/46 `elf_reader_bounds_tests` cases passed; I did not independently reproduce this local run. | <details><summary>Raw output from local checks</summary> ```text All conventions checks passed. /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-14121-fc04d8e9c3b4/head-fc04d8e9c3b4-219c33d5/tools/pr_test_quality.py': [Errno 2] No such file or directory fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:264: add_test_executable(elf_reader_bounds_tests fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:265: ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/ElfReaderBoundsTests.cpp fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:267: target_include_directories(elf_reader_bounds_tests PRIVATE fc04d8e9c3b4648498971d68b9a3d50702c6a257:core/relinker/CMakeLists.txt:271: add_test(NAME elf_reader_bounds COMMAND elf_reader_bounds_tests) { "findings": [ { "path": "core/relinker/relinker/tests/ElfReaderBoundsTests.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` </details> ## Negative control | Assertion | Mutation reported by author | Result | |---|---|---| | Bounds tests reject overflowing segment and table ranges, and reject Sony segments as virtual-address mappings | Relax `_rangeFits`; separately allow `TranslateVirtualAddress` to match non-`PT_LOAD` segments | PR description reports the corresponding tests failed under each mutation and all 46 passed after restoring the code; I did not rerun these mutations. | ## Findings **Blocking:** None found. **Non-blocking:** The test-quality warning is a confirmed false positive; the CMake file registers the test executable and the `elf_reader_bounds` CTest. ## Sources - [Sony segment boundary tests at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/fc04d8e9c3b4648498971d68b9a3d50702c6a257/core/relinker/relinker/tests/ElfReaderBoundsTests.cpp) - [CMake target and CTest registration](https://github.com/boykopovar/AnyPS5/blob/fc04d8e9c3b4648498971d68b9a3d50702c6a257/core/relinker/CMakeLists.txt#L264-L271) ## Not verified I did not independently rerun the author’s 46-case CTest command or mutation controls. Hosted relinker and ASan jobs passed; Linux/Windows product jobs were skipped.
MarcZX10 commented 2026-11-14 05:36:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T05:36:34Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed test changes shows a blocking defect, and the added cases exercise Sony segment parsing and bounds handling.

What I ran

Reviewed head 6b56631192b7fbcfcf1046b866942639af33b51e. I read the prepared description, commit list, manifest, diff, and the changed test file; no commands or tests were run.

Results

Check Result Note
Source review passed Added tests inspected
Tests not run Author reported 46 passing cases
Conventions and diff check not run Author reported both passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Test execution and the reported negative-control, conventions, and diff checks were not independently verified. No files were excluded by the review manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901943578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14121#pullrequestreview-5901943578). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T05:36:34Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed test changes shows a blocking defect, and the added cases exercise Sony segment parsing and bounds handling. ## What I ran Reviewed head `6b56631192b7fbcfcf1046b866942639af33b51e`. I read the prepared description, commit list, manifest, diff, and the changed test file; no commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Added tests inspected | | Tests | not run | Author reported 46 passing cases | | Conventions and diff check | not run | Author reported both passed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Test execution and the reported negative-control, conventions, and diff checks were not independently verified. No files were excluded by the review manifest. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-21 12:26:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:26:04Z.

Review: APPROVED


Reviewed — looks good

The added boundary tests appear consistent with the stated goal, and the full changed test file was reviewed at head ce0a7ac5a016ddec073df0ea33a55c37eb9b1ff0.

What I ran

No commands were run; the repository reader was unavailable as a plain command in this session. I read the prepared diff and the full changed test file through the pinned-head reader.

Results

Check Result Note
Change review passed Added test code reviewed
Unit tests not run Results in the PR description are author-reported
Convention and diff checks not run Results in the PR description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

The prepared bundle contains one changed file, and its full head text was read: core/relinker/relinker/tests/ElfReaderBoundsTests.cpp. No files were excluded. Build and test execution, the reported negative controls, conventions, and diff checks were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005168677 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14121#pullrequestreview-6005168677). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T12:26:04Z. **Review:** APPROVED --- # Reviewed — looks good The added boundary tests appear consistent with the stated goal, and the full changed test file was reviewed at head `ce0a7ac5a016ddec073df0ea33a55c37eb9b1ff0`. ## What I ran No commands were run; the repository reader was unavailable as a plain command in this session. I read the prepared diff and the full changed test file through the pinned-head reader. ## Results | Check | Result | Note | |---|---|---| | Change review | passed | Added test code reviewed | | Unit tests | not run | Results in the PR description are author-reported | | Convention and diff checks | not run | Results in the PR description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The prepared bundle contains one changed file, and its full head text was read: `core/relinker/relinker/tests/ElfReaderBoundsTests.cpp`. No files were excluded. Build and test execution, the reported negative controls, conventions, and diff checks were not independently verified. ## To get this to a good state Nothing is required.
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!14121
No description provided.