fix(relinker): reject overflowing signed unwind LEB128 values #2245

Merged
NumberGuan merged 1 commit from upstream-pr/2245 into main 2026-10-10 04:45:55 +00:00
NumberGuan commented 2026-10-09 13:06:36 +00:00 (Migrated from github.com)

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


What

EhFrameReader::leb accepts a tenth-byte payload of 1 for both unsigned and signed 64-bit LEB128. In the signed case, nine 0x80 bytes followed by 0x01 encode positive 2^63, which does not fit in int64_t. The reader accepts it and returns the bit pattern of INT64_MIN.

Use separate overflow limits: the tenth payload may be 0 or 0x7F for SLEB128, and 0 or 1 for ULEB128. This matches the LLVM 20.1.8 decoder. The existing error reports malformed unwind data instead of silently accepting the overflow.

Add a regression to the registered strict_nid_filter test. It reads a complete EH frame header, CIE and FDE through ReadExceptionFunctions. The fixture checks all 128 terminating payloads with two prefixes, in signed and unsigned CIE fields: 512 boundary combinations plus a normal short encoding. Accepted encodings must preserve the function range and targets; rejected ones must produce the overflow diagnostic.

This is independent of #1944, which changes LSDA handling in the same reader. git merge-tree combines the two branches 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 682d6f62.

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. Registration, conventions and whitespace checks passed. strict_nid_filter took 0.28 seconds. The existing tls_function_coverage test took 67.63 seconds; no repository timeout was changed.

With only the regression added to the original implementation, strict_nid_filter fails with Overflowing CIE LEB128 value was accepted. It passes with the one-line fix.

GitHub Actions passed Conventions and the relinker build/test matrix on Windows, Linux and macOS for 682d6f62: 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:4800816344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2245). Originally posted by [NumberGuan](https://github.com/NumberGuan) on 2026-10-09T13:06:36Z. --- ### What `EhFrameReader::leb` accepts a tenth-byte payload of `1` for both unsigned and signed 64-bit LEB128. In the signed case, nine `0x80` bytes followed by `0x01` encode positive 2^63, which does not fit in `int64_t`. The reader accepts it and returns the bit pattern of `INT64_MIN`. Use separate overflow limits: the tenth payload may be `0` or `0x7F` for SLEB128, and `0` or `1` for ULEB128. This matches the [LLVM 20.1.8 decoder](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/llvm/include/llvm/Support/LEB128.h#L169-L171). The existing error reports malformed unwind data instead of silently accepting the overflow. Add a regression to the registered `strict_nid_filter` test. It reads a complete EH frame header, CIE and FDE through `ReadExceptionFunctions`. The fixture checks all 128 terminating payloads with two prefixes, in signed and unsigned CIE fields: 512 boundary combinations plus a normal short encoding. Accepted encodings must preserve the function range and targets; rejected ones must produce the overflow diagnostic. This is independent of #1944, which changes LSDA handling in the same reader. `git merge-tree` combines the two branches 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 `682d6f62`. ```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. Registration, conventions and whitespace checks passed. `strict_nid_filter` took 0.28 seconds. The existing `tls_function_coverage` test took 67.63 seconds; no repository timeout was changed. With only the regression added to the original implementation, `strict_nid_filter` fails with `Overflowing CIE LEB128 value was accepted`. It passes with the one-line fix. GitHub Actions passed Conventions and the relinker build/test matrix on Windows, Linux and macOS for `682d6f62`: [Build run](https://github.com/boykopovar/AnyPS5/actions/runs/37934530460), [Conventions run](https://github.com/boykopovar/AnyPS5/actions/runs/37934529989). 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:35:43 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the complete two-file diff and verified the boundary logic: at bit 63, signed payloads allow only 0 or 0x7f, while unsigned payloads allow only 0 or 1; continued tenth bytes still hit the existing unterminated-value guard. I built the full relinker-only target and ran on the exact head (1/1 passed). Conventions and diff checks pass, and the official Linux, Windows, and macOS relinker jobs are green. No blocking issues found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5470783185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2245#pullrequestreview-5470783185). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T13:35:43Z. **Review:** APPROVED --- Reviewed the complete two-file diff and verified the boundary logic: at bit 63, signed payloads allow only 0 or 0x7f, while unsigned payloads allow only 0 or 1; continued tenth bytes still hit the existing unterminated-value guard. I built the full relinker-only target and ran on the exact head (1/1 passed). Conventions and diff checks pass, and the official Linux, Windows, and macOS relinker jobs are green. No blocking issues found.
MarcZX10 commented 2026-10-09 13:36:00 +00:00 (Migrated from github.com)

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

Review: COMMENTED


For clarity, the focused CTest I ran on this head was strict_nid_filter (1/1 passed). The full relinker-only build and the official Linux, Windows, and macOS relinker jobs also passed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5470787067 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2245#pullrequestreview-5470787067). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T13:36:00Z. **Review:** COMMENTED --- For clarity, the focused CTest I ran on this head was `strict_nid_filter` (1/1 passed). The full relinker-only build and the official Linux, Windows, and macOS relinker jobs also passed.
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!2245
No description provided.