fix(relinker): reject truncated EH frame headers #2256

Merged
NumberGuan merged 1 commit from upstream-pr/2256 into main 2026-10-10 04:46:09 +00:00
NumberGuan commented 2026-10-09 13:24:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NumberGuan on 2026-10-09T13:24:31Z.


What

EhFrameReader::Read checks the segment boundary inside the FDE table loop. When the decoded count is zero, that loop never runs: a truncated PT_GNU_EH_FRAME header can consume bytes beyond its declared size and still be accepted. A synthetic header declaring one byte currently relinks successfully.

Reject a segment shorter than the four encoding bytes, and reject a decoded header whose cursor exceeds the declared segment size before using its count. The LSB definition of PT_GNU_EH_FRAME specifies the location and size of .eh_frame_hdr.

The shared reader is used by strict NID filtering (unused-filter=2) and Windows TLS code analysis. Ordinary Linux conversion with filtering disabled does not use this reader and is outside this change.

Extend the registered linux_eh_frame_header integration test with fixed-width and ULEB128 headers. Every shorter nonempty segment must exit 2 with the new diagnostic, leave the input unchanged and write no executable. Complete headers must still convert. The matrix covers 44 rejection cases and four valid controls across Linux strict filtering and Windows conversion.

This is independent of #2245's signed LEB128 overflow check and #1944's LSDA handling. git merge-tree combines this branch with each of them without conflicts. No dependency.

Tested

Windows x64, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Ninja Release, Python 3.12.14. Based on upstream d70b8998; contribution ec5a2019.

cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON
cmake --build build-relinker --parallel 4
ctest --test-dir build-relinker --output-on-failure --timeout 120 --no-tests=error --parallel 2
python tools/check_test_registration.py build-relinker
python tools/check_conventions.py --base origin/main
git diff origin/main --check

All 40 registered test groups passed in 70.14 seconds. Registration, conventions and whitespace checks passed. The focused regression took 1.57 seconds. The existing tls_function_coverage test took 64.66 seconds in the full run; no repository timeout was changed.

With only the regression added to upstream d70b8998, the registered test fails because bounds-linux-strict-fixed-1 returns 0 and writes an executable. With the three-line fix it passes, including all 44 malformed inputs and the four valid controls.

GitHub Actions passed Conventions and the relinker build/test matrix on Windows, Linux and macOS for ec5a2019: Build run, Conventions run. The full Linux and Windows build jobs were skipped under the repository's pull-request policy. System-library builds and game/PS5 tests were not run locally.

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; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source; none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, Codex;
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801028178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2256). Originally posted by [NumberGuan](https://github.com/NumberGuan) on 2026-10-09T13:24:31Z. --- ### What `EhFrameReader::Read` checks the segment boundary inside the FDE table loop. When the decoded count is zero, that loop never runs: a truncated `PT_GNU_EH_FRAME` header can consume bytes beyond its declared size and still be accepted. A synthetic header declaring one byte currently relinks successfully. Reject a segment shorter than the four encoding bytes, and reject a decoded header whose cursor exceeds the declared segment size before using its count. The [LSB definition of PT_GNU_EH_FRAME](https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/progheader.html) specifies the location and size of `.eh_frame_hdr`. The shared reader is used by strict NID filtering (`unused-filter=2`) and Windows TLS code analysis. Ordinary Linux conversion with filtering disabled does not use this reader and is outside this change. Extend the registered `linux_eh_frame_header` integration test with fixed-width and ULEB128 headers. Every shorter nonempty segment must exit 2 with the new diagnostic, leave the input unchanged and write no executable. Complete headers must still convert. The matrix covers 44 rejection cases and four valid controls across Linux strict filtering and Windows conversion. This is independent of #2245's signed LEB128 overflow check and #1944's LSDA handling. `git merge-tree` combines this branch with each of them without conflicts. No dependency. ### Tested Windows x64, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Ninja Release, Python 3.12.14. Based on upstream `d70b8998`; contribution `ec5a2019`. ```text cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON cmake --build build-relinker --parallel 4 ctest --test-dir build-relinker --output-on-failure --timeout 120 --no-tests=error --parallel 2 python tools/check_test_registration.py build-relinker python tools/check_conventions.py --base origin/main git diff origin/main --check ``` All 40 registered test groups passed in 70.14 seconds. Registration, conventions and whitespace checks passed. The focused regression took 1.57 seconds. The existing `tls_function_coverage` test took 64.66 seconds in the full run; no repository timeout was changed. With only the regression added to upstream `d70b8998`, the registered test fails because `bounds-linux-strict-fixed-1` returns 0 and writes an executable. With the three-line fix it passes, including all 44 malformed inputs and the four valid controls. GitHub Actions passed Conventions and the relinker build/test matrix on Windows, Linux and macOS for `ec5a2019`: [Build run](https://github.com/boykopovar/AnyPS5/actions/runs/37936625723), [Conventions run](https://github.com/boykopovar/AnyPS5/actions/runs/37936625455). The full Linux and Windows build jobs were skipped under the repository's pull-request policy. System-library builds and game/PS5 tests were not run locally. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source; none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, Codex;
MarcZX10 commented 2026-10-09 13:38:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:38:40Z.

Review: APPROVED


Reviewed the complete diff. The size checks reject short program-header segments and any decoded fixed-width or LEB128 header whose cursor crosses the declared segment; the tests verify truncated inputs write no output while complete controls still convert. The relinker-only build and linux_eh_frame_header passed locally (1/1), Conventions passed, and the official Linux, Windows, and macOS relinker jobs are green. This remains separate from #2245, which rejects LEB128 value overflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5470820299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2256#pullrequestreview-5470820299). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T13:38:40Z. **Review:** APPROVED --- Reviewed the complete diff. The size checks reject short program-header segments and any decoded fixed-width or LEB128 header whose cursor crosses the declared segment; the tests verify truncated inputs write no output while complete controls still convert. The relinker-only build and `linux_eh_frame_header` passed locally (1/1), Conventions passed, and the official Linux, Windows, and macOS relinker jobs are green. This remains separate from #2245, which rejects LEB128 value overflow.
github-actions[bot] commented 2026-10-10 01:49:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T01:49:34Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2274 core/relinker/relinker/tests/test_linux_eh_frame_header.py L51-54
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092364323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2256#issuecomment-6092364323). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T01:49:34Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2274 | `core/relinker/relinker/tests/test_linux_eh_frame_header.py` [L51-54](https://github.com/boykopovar/AnyPS5/blob/698254f048952385120dba5b7af7658be2fd49e6/core/relinker/relinker/tests/test_linux_eh_frame_header.py#L51-L54) | | |
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!2256
No description provided.