fix(relinker): bound DT_RELA table range #1446

Merged
sktharunbalaji13-cmd merged 2 commits from upstream-pr/1446 into main 2026-10-10 01:01:43 +00:00
sktharunbalaji13-cmd commented 2026-10-08 06:52:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-08T06:52:37Z.


What

The relinker accepted an ELF whose declared relocation table did not lie inside the input file, and then wrote that offset into the output it generated.

The defect is specific to an empty relocation table. #917 added the overflow-safe per-entry bound (relaEntryPos, RelinkerPipeline.cpp), but that check only runs inside the extractRela loop, and the loop body never executes when DT_RELASZ is 0. Nothing reads the table, so nothing rejects it, and the bad offset travels on — as @Dextroid17 measured by scanning the produced file for each (tag, value) pair:

empty-past-eof   (DT_OS_RELA 0x2000)               DT_OS_RELASZ 0   DT_RELA 0   DT_RELASZ 0
empty-offset-max (DT_OS_RELA 0xfffffffffffffffe)   DT_OS_RELASZ 0   DT_RELA 0   DT_RELASZ 0

So the conversion hands a title a dynamic table pointing outside the file, with a size of zero. That is the "does exactly what it should or throws" case rather than a message preference, and it is why this is worth merging instead of cosmetics.

This is also what separates it from the table-level check @oneandonlydean asked to drop from #1272. That hunk was about the read — no read can leave the file, because relaEntryPos already bounds it. This is about what gets written, which relaEntryPos cannot reach.

The fix validates the declared table range before the table is consumed, using the same shape as the existing dynamic string-table guard:

if (dynStrTabOffset > raw.size() || dynStrTabSize > raw.size() - dynStrTabOffset)
    throw RelinkerException("Dynamic string table is out of bounds", dynStrTabOffset);

if (dynRelaOffset > raw.size() || dynRelaSize > raw.size() - dynRelaOffset)
    throw RelinkerException("Relocation table is out of bounds", dynRelaOffset);

The first term short-circuits, so the subtraction cannot wrap and offset > size || size > size - offset decides both an offset past EOF and an offset plus size past EOF, for the system-V path (already translated by TranslateVirtualAddress) and the Sony DT_OS_RELA path (raw). #1424 covers the separate DT_JMPREL/DT_PLTRELSZ table and is already merged; this PR covers the DT_RELA/DT_OS_RELA table itself.

Malformed inputs now fail with the table named, in both output modes:

--windows   bad-offset-past-eof   exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x9000)
--to-intel  bad-offset-past-eof   exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x9000)
--windows   bad-range-past-eof    exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x7ff0)
--to-intel  bad-huge-size         exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x700)

Tests — tests/RelocTableBoundsTests.cpp (CTest reloc_table_bounds) is C++ on ElfFixture.hpp / RelinkerProcess.hpp, registered explicitly in core/relinker/CMakeLists.txt like RelaBoundsTests.cpp, and runs every case under --windows and --to-intel (the fixture's spare program headers are what let the Linux path reach the code under test). It keeps valid controls (an empty in-file table, an empty DT_OS_RELA table, a table holding one relocation entry), both tag families, and a case whose address no segment maps.

rela_bounds (#917) expectation, updated deliberately. Both of its cases are now answered by the table guard before any entry is read — case 1 has an offset near UINT64_MAX, case 2 has offset + size past the end — so RelaBoundsTests.cpp:38 now expects Relocation table is out of bounds. Keeping the old Relocation entry out of bounds expectation there would mean removing the guard for those inputs, which is the defect itself. The two cases are unchanged otherwise and still require a non-zero exit, so the regression is not weakened: with the guard reverted, rela_bounds fails with "Relinker did not report the table as out of bounds for a table whose offset is near UINT64_MAX".

Tested

  • Linux x86_64, GCC 13.3, Release (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON): full relinker CTest suite 39/39 passed, including reloc_table_bounds, rela_bounds, jmprel_table_bounds and string_table_bounds
  • cmake --build build-linux --target relinker rela_bounds_tests reloc_table_bounds_tests
  • ctest --test-dir build-linux -R '^(reloc_table_bounds|rela_bounds)$' → 2/2 passed
  • Windows, MinGW-w64 GCC 15.2.0 (winlibs), Release, Ninja: cmake --build build --target relinker, affected relinker CTest suite 25/25 passed
  • git diff --check
  • python tools/check_conventions.py ... → All conventions checks passed
  • pre-fix proof repeated on this head: with only the RelinkerPipeline.cpp guard reverted, reloc_table_bounds fails with "Relinker accepted an empty relocation table whose offset is past the end of the file for --windows" and rela_bounds fails as above; with the guard restored both pass
  • --to-intel no longer stops at Not enough program header slots: the fixture carries the spare program headers, and both modes reject the malformed tables with the message above
  • The full 400+ test suite was not run in the Windows environment because the unrelated libs, FFmpeg and guest targets are not built there; the Linux run covers the relinker in full.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #1424 covers DT_JMPREL/DT_PLTRELSZ and is merged; this PR is independently scoped to the DT_RELA table range
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4783025420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-08T06:52:37Z. --- ### What The relinker accepted an ELF whose declared relocation table did not lie inside the input file, and then **wrote that offset into the output it generated**. The defect is specific to an **empty** relocation table. #917 added the overflow-safe per-entry bound (`relaEntryPos`, `RelinkerPipeline.cpp`), but that check only runs inside the `extractRela` loop, and the loop body never executes when `DT_RELASZ` is `0`. Nothing reads the table, so nothing rejects it, and the bad offset travels on — as @Dextroid17 measured by scanning the produced file for each `(tag, value)` pair: ``` empty-past-eof (DT_OS_RELA 0x2000) DT_OS_RELASZ 0 DT_RELA 0 DT_RELASZ 0 empty-offset-max (DT_OS_RELA 0xfffffffffffffffe) DT_OS_RELASZ 0 DT_RELA 0 DT_RELASZ 0 ``` So the conversion hands a title a dynamic table pointing outside the file, with a size of zero. That is the "does exactly what it should or throws" case rather than a message preference, and it is why this is worth merging instead of cosmetics. This is also what separates it from the table-level check @oneandonlydean asked to drop from #1272. That hunk was about the **read** — no read can leave the file, because `relaEntryPos` already bounds it. This is about what gets **written**, which `relaEntryPos` cannot reach. The fix validates the declared table range before the table is consumed, using the same shape as the existing dynamic string-table guard: ```cpp if (dynStrTabOffset > raw.size() || dynStrTabSize > raw.size() - dynStrTabOffset) throw RelinkerException("Dynamic string table is out of bounds", dynStrTabOffset); if (dynRelaOffset > raw.size() || dynRelaSize > raw.size() - dynRelaOffset) throw RelinkerException("Relocation table is out of bounds", dynRelaOffset); ``` The first term short-circuits, so the subtraction cannot wrap and `offset > size || size > size - offset` decides both an offset past EOF and an offset plus size past EOF, for the system-V path (already translated by `TranslateVirtualAddress`) and the Sony `DT_OS_RELA` path (raw). #1424 covers the separate `DT_JMPREL`/`DT_PLTRELSZ` table and is already merged; this PR covers the `DT_RELA`/`DT_OS_RELA` table itself. Malformed inputs now fail with the table named, in both output modes: ``` --windows bad-offset-past-eof exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x9000) --to-intel bad-offset-past-eof exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x9000) --windows bad-range-past-eof exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x7ff0) --to-intel bad-huge-size exit=2 output=False FAIL: Relocation table is out of bounds (offset 0x700) ``` **Tests** — `tests/RelocTableBoundsTests.cpp` (CTest `reloc_table_bounds`) is C++ on `ElfFixture.hpp` / `RelinkerProcess.hpp`, registered explicitly in `core/relinker/CMakeLists.txt` like `RelaBoundsTests.cpp`, and runs every case under `--windows` and `--to-intel` (the fixture's spare program headers are what let the Linux path reach the code under test). It keeps valid controls (an empty in-file table, an empty `DT_OS_RELA` table, a table holding one relocation entry), both tag families, and a case whose address no segment maps. **`rela_bounds` (#917) expectation, updated deliberately.** Both of its cases are now answered by the table guard before any entry is read — case 1 has an offset near `UINT64_MAX`, case 2 has `offset + size` past the end — so `RelaBoundsTests.cpp:38` now expects `Relocation table is out of bounds`. Keeping the old `Relocation entry out of bounds` expectation there would mean removing the guard for those inputs, which is the defect itself. The two cases are unchanged otherwise and still require a non-zero exit, so the regression is not weakened: with the guard reverted, `rela_bounds` fails with *"Relinker did not report the table as out of bounds for a table whose offset is near UINT64_MAX"*. ### Tested - Linux x86_64, GCC 13.3, Release (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`): full relinker CTest suite **39/39 passed**, including `reloc_table_bounds`, `rela_bounds`, `jmprel_table_bounds` and `string_table_bounds` - `cmake --build build-linux --target relinker rela_bounds_tests reloc_table_bounds_tests` - `ctest --test-dir build-linux -R '^(reloc_table_bounds|rela_bounds)$'` → 2/2 passed - Windows, MinGW-w64 GCC 15.2.0 (winlibs), Release, Ninja: `cmake --build build --target relinker`, affected relinker CTest suite **25/25 passed** - `git diff --check` - `python tools/check_conventions.py ...` → All conventions checks passed - pre-fix proof repeated on this head: with only the `RelinkerPipeline.cpp` guard reverted, `reloc_table_bounds` fails with *"Relinker accepted an empty relocation table whose offset is past the end of the file for --windows"* and `rela_bounds` fails as above; with the guard restored both pass - `--to-intel` no longer stops at `Not enough program header slots`: the fixture carries the spare program headers, and both modes reject the malformed tables with the message above - The full 400+ test suite was not run in the Windows environment because the unrelated `libs`, FFmpeg and guest targets are not built there; the Linux run covers the relinker in full. ### 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 (`NotImplemented_nid_no_patch`); silent stubs are listed in `TechnicalDebt` - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #1424 covers `DT_JMPREL`/`DT_PLTRELSZ` and is merged; this PR is independently scoped to the `DT_RELA` table range - [x] AI-assisted: yes
Dextroid17 commented 2026-10-08 12:27:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T12:27:33Z.


Correction to my first read, with measurements: I had this filed as covered by #917, and it is not.

Running your own script against a clean current main (1081602d) says the same thing you do, and says something useful about which case is the one that gets through:

nonempty-past-eof   windows   rc=2   FAIL: Relocation entry out of bounds (offset 0x2000)
empty-past-eof      windows   rc=0   output written
empty-offset-max    windows   rc=0   output written

So the non-empty case is already rejected — that is #917's per-entry bound, relaEntryPos at RelinkerPipeline.cpp:190, and it is why those cases in your script pass on main. The case that gets through is the empty table with an out-of-range offset: the loop body never runs, so the bound is never reached, and the conversion succeeds.

And the offset does reach the output, which is what makes this worth merging rather than cosmetic. Scanning the produced file for each (tag, value) pair:

empty-past-eof   (DT_OS_RELA 0x2000)             DT_OS_RELASZ 0   DT_RELA 0   DT_RELASZ 0
empty-offset-max (DT_OS_RELA 0xfffffffffffffffe) DT_OS_RELASZ 0   DT_RELA 0   DT_RELASZ 0

So the conversion writes an offset outside the file into the dynamic table it hands to a title, with a size of 0. That is the "does exactly what it should or throws" case rather than a message preference.

One thing worth saying in the body, because it is the difference from the change I withdrew. In #1272 I carried the same table-level check as a second hunk and @oneandonlydean told me to drop it — "#917 is on main and now bounds extractRelativethroughrelaEntryPos, so that hunk is no longer needed". That was about the **read**, and he was right: no read can leave the file. This is about what gets **written**, which is a case relaEntryPos` cannot reach. Naming that distinction in the description is what separates this from the hunk that was dropped.

One test note. Your script only exercises --windows. Under --to-intel this fixture fails earlier and for an unrelated reason — FAIL: Not enough program header slots: need 5, available 3, the image carries three program headers — so the Linux path is never reached. If the OS tag matters for the Linux output too, a fixture with five program headers would cover it.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6059847137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#issuecomment-6059847137). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T12:27:33Z. --- Correction to my first read, with measurements: I had this filed as covered by #917, and it is not. Running **your own script** against a clean current `main` (`1081602d`) says the same thing you do, and says something useful about which case is the one that gets through: ``` nonempty-past-eof windows rc=2 FAIL: Relocation entry out of bounds (offset 0x2000) empty-past-eof windows rc=0 output written empty-offset-max windows rc=0 output written ``` So the non-empty case is already rejected — that is #917's per-entry bound, `relaEntryPos` at `RelinkerPipeline.cpp:190`, and it is why those cases in your script pass on `main`. The case that gets through is the **empty table with an out-of-range offset**: the loop body never runs, so the bound is never reached, and the conversion succeeds. **And the offset does reach the output**, which is what makes this worth merging rather than cosmetic. Scanning the produced file for each `(tag, value)` pair: ``` empty-past-eof (DT_OS_RELA 0x2000) DT_OS_RELASZ 0 DT_RELA 0 DT_RELASZ 0 empty-offset-max (DT_OS_RELA 0xfffffffffffffffe) DT_OS_RELASZ 0 DT_RELA 0 DT_RELASZ 0 ``` So the conversion writes an offset outside the file into the dynamic table it hands to a title, with a size of 0. That is the "does exactly what it should or throws" case rather than a message preference. **One thing worth saying in the body, because it is the difference from the change I withdrew.** In #1272 I carried the same table-level check as a second hunk and @oneandonlydean told me to drop it — "`#917 is on main and now bounds `extractRelative` through `relaEntryPos`, so that hunk is no longer needed". That was about the **read**, and he was right: no read can leave the file. This is about what gets **written**, which is a case `relaEntryPos` cannot reach. Naming that distinction in the description is what separates this from the hunk that was dropped. **One test note.** Your script only exercises `--windows`. Under `--to-intel` this fixture fails earlier and for an unrelated reason — `FAIL: Not enough program header slots: need 5, available 3`, the image carries three program headers — so the Linux path is never reached. If the OS tag matters for the Linux output too, a fixture with five program headers would cover it. Written with AI assistance.
Dextroid17 commented 2026-10-08 13:19:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T13:19:16Z.


Two things that would let you cover the Linux half of this, since your fixture currently stops before it reaches the code under test.

The --to-intel run never gets there. With this image it exits with FAIL: Not enough program header slots: need 5, available 3 — the image declares exactly three program headers (e_phnum = 3 at offset 56) and the Linux conversion wants spare slots. The rest of the suite already solves this: core/relinker/relinker/tests/ElfFixture.hpp declares e_phnum = 2 + kSpareProgramHeaders (five) and writes the three spare entries as type 0x6FFFFF01. Adding spare slots to your fixture — declared, even if empty — is what makes the Linux path reachable, and then the same assertion runs under both modes.

  ElfFixture.hpp:20   inline constexpr std::uint16_t kSpareProgramHeaders = 3;
  ElfFixture.hpp:60   Write<std::uint16_t>(image, 56, 2 + kSpareProgramHeaders);
  ElfFixture.hpp:65   for (index = 2; index < 2 + kSpareProgramHeaders; ++index)
                          WriteProgramHeader(image, index, 0x6FFFFF01, 0, 0, 0, 0, 1);

If you would rather keep it in Python, test_guest_intel_trampolines.py:127 is the pattern for invoking --to-intel from a test in this tree.

On the switch itself, purely as a suggestion: with the non-empty case ignored and a bogus-but-unused offset accepted today, the check you are adding is what makes the conversion refuse to hand a title an out-of-range table offset. I measured that the offset is carried into the output in both the DT_OS_RELA and DT_OS_JMPREL cases, which is the argument I would put in the description — it is what separates this from the same check I was told to drop from #1272, where the bound was about the read.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060766271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#issuecomment-6060766271). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T13:19:16Z. --- Two things that would let you cover the Linux half of this, since your fixture currently stops before it reaches the code under test. **The `--to-intel` run never gets there.** With this image it exits with `FAIL: Not enough program header slots: need 5, available 3` — the image declares exactly three program headers (`e_phnum = 3` at offset 56) and the Linux conversion wants spare slots. The rest of the suite already solves this: `core/relinker/relinker/tests/ElfFixture.hpp` declares `e_phnum = 2 + kSpareProgramHeaders` (five) and writes the three spare entries as type `0x6FFFFF01`. Adding spare slots to your fixture — declared, even if empty — is what makes the Linux path reachable, and then the same assertion runs under both modes. ``` ElfFixture.hpp:20 inline constexpr std::uint16_t kSpareProgramHeaders = 3; ElfFixture.hpp:60 Write<std::uint16_t>(image, 56, 2 + kSpareProgramHeaders); ElfFixture.hpp:65 for (index = 2; index < 2 + kSpareProgramHeaders; ++index) WriteProgramHeader(image, index, 0x6FFFFF01, 0, 0, 0, 0, 1); ``` If you would rather keep it in Python, `test_guest_intel_trampolines.py:127` is the pattern for invoking `--to-intel` from a test in this tree. **On the switch itself, purely as a suggestion:** with the non-empty case ignored and a bogus-but-unused offset accepted today, the check you are adding is what makes the conversion refuse to hand a title an out-of-range table offset. I measured that the offset is carried into the output in both the `DT_OS_RELA` and `DT_OS_JMPREL` cases, which is the argument I would put in the description — it is what separates this from the same check I was told to drop from #1272, where the bound was about the *read*. Written with AI assistance.
adriadam10 commented 2026-10-08 13:51:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:51:18Z.

Review: CHANGES_REQUESTED


The guard itself looks right (same shape as the string-table check, and the empty-table-with-bad-offset case is real, as @Dextroid17 measured). Merged onto current main (b3fcd6d6c), though, two tests fail:

  • reloc_table_bounds (yours) fails on range-past-eof (rela=0xFF0, relasz=0x100): it exits with Invalid DT_RELASZ value (RelinkerPipeline.cpp:148, 0x100 is not a multiple of 24) before reaching the new check, so that case does not test it. Use a size that is a multiple of 24 (e.g. 0x108 at 0xFF0).
  • rela_bounds (#917, on main) fails: RelaBoundsTests.cpp:38 expects Relocation entry out of bounds for a table at an offset near UINT64_MAX, and now gets Relocation table is out of bounds (RelinkerPipeline.cpp:166). Either keep that case reaching the old message or update that expectation deliberately and say so in the PR.
  • Tests in this area are C++ (relinker/tests/*Tests.cpp on ElfFixture.hpp/RelinkerProcess.hpp, registered explicitly in core/relinker/CMakeLists.txt); please port the new one, as RelaBoundsTests.cpp does. ElfFixture.hpp also has the spare program headers, so the same cases run under --to-intel as well as --windows (your fixture stops at Not enough program header slots there, as Dextroid17 noted).
  • Add to the description that the point is the offset written to the output for an empty table, which relaEntryPos (#917) cannot reach.
  • No CI ran on the current head; run the tests locally after the changes above.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5457642323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#pullrequestreview-5457642323). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T13:51:18Z. **Review:** CHANGES_REQUESTED --- The guard itself looks right (same shape as the string-table check, and the empty-table-with-bad-offset case is real, as @Dextroid17 measured). Merged onto current `main` (b3fcd6d6c), though, two tests fail: - `reloc_table_bounds` (yours) fails on `range-past-eof` (`rela=0xFF0, relasz=0x100`): it exits with `Invalid DT_RELASZ value` (`RelinkerPipeline.cpp:148`, 0x100 is not a multiple of 24) before reaching the new check, so that case does not test it. Use a size that is a multiple of 24 (e.g. 0x108 at 0xFF0). - `rela_bounds` (#917, on `main`) fails: `RelaBoundsTests.cpp:38` expects `Relocation entry out of bounds` for a table at an offset near UINT64_MAX, and now gets `Relocation table is out of bounds` (`RelinkerPipeline.cpp:166`). Either keep that case reaching the old message or update that expectation deliberately and say so in the PR. - Tests in this area are C++ (`relinker/tests/*Tests.cpp` on `ElfFixture.hpp`/`RelinkerProcess.hpp`, registered explicitly in `core/relinker/CMakeLists.txt`); please port the new one, as `RelaBoundsTests.cpp` does. `ElfFixture.hpp` also has the spare program headers, so the same cases run under `--to-intel` as well as `--windows` (your fixture stops at `Not enough program header slots` there, as Dextroid17 noted). - Add to the description that the point is the offset written to the output for an empty table, which `relaEntryPos` (#917) cannot reach. - No CI ran on the current head; run the tests locally after the changes above.
adriadam10 commented 2026-10-08 14:06:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T14:06:52Z.

Review: CHANGES_REQUESTED


Merged onto current main, reloc_table_bounds now passes (the range-past-eof size is fixed), but two things from the earlier review are still open:

  • rela_bounds (#917, on main) fails: RelaBoundsTests.cpp:38 expects Relocation entry out of bounds for a table at an offset near UINT64_MAX, and now gets Relocation table is out of bounds (RelinkerPipeline.cpp:168). Either keep that case reaching the old message, or update that expectation deliberately and say so in the PR.
  • The new test is Python; tests in this area are C++ (relinker/tests/*Tests.cpp on ElfFixture.hpp/RelinkerProcess.hpp, registered explicitly in core/relinker/CMakeLists.txt), as RelaBoundsTests.cpp does. ElfFixture.hpp also has the spare program headers, so the same cases run under --to-intel as well as --windows.
  • Add to the description that the point is the offset written to the output for an empty table, which relaEntryPos (#917) cannot reach (see @Dextroid17's measurements above).

Checked: the new test fails without the RelinkerPipeline.cpp change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5457854803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#pullrequestreview-5457854803). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T14:06:52Z. **Review:** CHANGES_REQUESTED --- Merged onto current `main`, `reloc_table_bounds` now passes (the `range-past-eof` size is fixed), but two things from the earlier review are still open: - `rela_bounds` (#917, on `main`) fails: `RelaBoundsTests.cpp:38` expects `Relocation entry out of bounds` for a table at an offset near UINT64_MAX, and now gets `Relocation table is out of bounds` (`RelinkerPipeline.cpp:168`). Either keep that case reaching the old message, or update that expectation deliberately and say so in the PR. - The new test is Python; tests in this area are C++ (`relinker/tests/*Tests.cpp` on `ElfFixture.hpp`/`RelinkerProcess.hpp`, registered explicitly in `core/relinker/CMakeLists.txt`), as `RelaBoundsTests.cpp` does. `ElfFixture.hpp` also has the spare program headers, so the same cases run under `--to-intel` as well as `--windows`. - Add to the description that the point is the offset written to the output for an empty table, which `relaEntryPos` (#917) cannot reach (see @Dextroid17's measurements above). Checked: the new test fails without the `RelinkerPipeline.cpp` change.
Dextroid17 commented 2026-10-08 14:17:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T14:17:32Z.


Ran your fixture in both conversion modes, against your branch and against main, to answer the "does this need the Linux path covered too" question with numbers.

First, good news: this now merges cleanly onto current main — no conflicts, unlike most of the relinker queue this morning.

With your change, every case is rejected in both modes — and it needs no spare program header slots, because your guard runs upstream of the converter:

empty-past-eof     --windows  rc=2  FAIL: Relocation table is out of bounds (offset 0x2000)
empty-past-eof     --to-intel rc=2  FAIL: Relocation table is out of bounds (offset 0x2000)
empty-offset-max   --windows  rc=2  FAIL: Relocation table is out of bounds (offset 0xfffffffffffffffe)
empty-offset-max   --to-intel rc=2  FAIL: Relocation table is out of bounds (offset 0xfffffffffffffffe)
nonempty-past-eof  --windows  rc=2  FAIL: Relocation table is out of bounds (offset 0x2000)
nonempty-past-eof  --to-intel rc=2  FAIL: Relocation table is out of bounds (offset 0x2000)

On main, the same fixtures: the non-empty case is rejected by #917's per-entry bound in both modes, and the empty-table cases go through — --windows writes an output, and --to-intel does too once the image declares spare program header slots, with the same garbage inside:

  DT_OS_RELA 0x2000    DT_OS_RELASZ 0    (Linux output)
  DT_OS_RELA 0x2000    DT_OS_RELASZ 0    (Windows output)

So this is not a Windows-only case: the Linux path keeps the bogus offset too, once it gets far enough to run. That is the strongest version of the argument for the description, and it is worth a --to-intel case in the script so the claim is covered by the Linux job as well as the Windows one — with your guard everything rejects before the converter, so both modes assert the same message with no output.

One caveat on my method, so you do not chase it: the spare slots I declared are PT_LOOS+1 with zero size, exactly as ElfFixture.hpp writes its spares. Those make the Windows path fail earlier with FAIL: Code analysis: invalid SCE table on main, which is an artifact of my synthetic headers rather than of your change — ignore the with-spares Windows rows. The Linux rows are the meaningful ones.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6061864592 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#issuecomment-6061864592). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T14:17:32Z. --- Ran your fixture in both conversion modes, against your branch and against `main`, to answer the "does this need the Linux path covered too" question with numbers. **First, good news: this now merges cleanly onto current `main`** — no conflicts, unlike most of the relinker queue this morning. **With your change, every case is rejected in both modes** — and it needs no spare program header slots, because your guard runs upstream of the converter: ``` empty-past-eof --windows rc=2 FAIL: Relocation table is out of bounds (offset 0x2000) empty-past-eof --to-intel rc=2 FAIL: Relocation table is out of bounds (offset 0x2000) empty-offset-max --windows rc=2 FAIL: Relocation table is out of bounds (offset 0xfffffffffffffffe) empty-offset-max --to-intel rc=2 FAIL: Relocation table is out of bounds (offset 0xfffffffffffffffe) nonempty-past-eof --windows rc=2 FAIL: Relocation table is out of bounds (offset 0x2000) nonempty-past-eof --to-intel rc=2 FAIL: Relocation table is out of bounds (offset 0x2000) ``` **On `main`, the same fixtures:** the non-empty case is rejected by #917's per-entry bound in both modes, and the empty-table cases go through — `--windows` writes an output, and `--to-intel` does too **once the image declares spare program header slots**, with the same garbage inside: ``` DT_OS_RELA 0x2000 DT_OS_RELASZ 0 (Linux output) DT_OS_RELA 0x2000 DT_OS_RELASZ 0 (Windows output) ``` So this is **not a Windows-only case**: the Linux path keeps the bogus offset too, once it gets far enough to run. That is the strongest version of the argument for the description, and it is worth a `--to-intel` case in the script so the claim is covered by the Linux job as well as the Windows one — with your guard everything rejects before the converter, so both modes assert the same message with no output. **One caveat on my method, so you do not chase it:** the spare slots I declared are `PT_LOOS+1` with zero size, exactly as `ElfFixture.hpp` writes its spares. Those make the *Windows* path fail earlier with `FAIL: Code analysis: invalid SCE table` on `main`, which is an artifact of my synthetic headers rather than of your change — ignore the with-spares Windows rows. The Linux rows are the meaningful ones. Written with AI assistance.
Dextroid17 commented 2026-10-08 14:44:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T14:44:10Z.


Two things from @adriadam10's review are still open, and both have short, concrete answers — here is the pattern, so the port is mechanical rather than a rewrite.

1. The C++ port. RelaBoundsTests.cpp (on main, from #917) is the whole template: same fixture, same helpers, same assertions, one file. What you need:

  file    core/relinker/relinker/tests/RelocTableBoundsTests.cpp
  model   core/relinker/relinker/tests/RelaBoundsTests.cpp
  reg     core/relinker/CMakeLists.txt, next to rela_bounds_tests —
            add_test_executable(reloc_table_bounds_tests
                ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/RelocTableBoundsTests.cpp)
            add_test(NAME reloc_table_bounds COMMAND reloc_table_bounds_tests $<TARGET_FILE:relinker>)

The includes give you everything: ElfFixture.hpp (Bytes, MakeExecutable, Write), RelinkerProcess.hpp (TempDirectory, WriteFile, RunRelinker returning {ExitCode, Output}). The shape that already works:

  using namespace RelinkerTests;                       // as RelaBoundsTests.cpp does
  constexpr std::size_t kRelaTag = 4;                  // the dynamic slots that file uses
  constexpr std::size_t kRelaSzTag = 5;
  constexpr std::int64_t kDtOsRela = 0x6100002f;
  constexpr std::int64_t kDtRelaSz = 8;

  Bytes image = MakeExecutable(kCode);
  Write<std::int64_t>(image, kTagBase + kRelaTag * 16, kDtOsRela);
  Write<std::uint64_t>(image, kTagBase + kRelaTag * 16 + 8, 0x2000);   // the empty-table case
  Write<std::int64_t>(image, kTagBase + kRelaSzTag * 16, kDtRelaSz);
  Write<std::uint64_t>(image, kTagBase + kRelaSzTag * 16 + 8, 0);      // size 0

Two things that make this cheaper than the Python version:

  • It carries the tag indices with it. RelaBoundsTests.cpp writes the OS RELA pair at slots 4 and 5 of the C++ fixture's dynamic array; your Python fixture builds its own tag list, so the indices are not portable. Copy the C++ constants, not the Python list.
  • Both modes come free. MakeExecutable already declares 2 + kSpareProgramHeaders program headers (ElfFixture.hpp:20,60,65), so the same image reaches the converter under --to-intel as well as --windows — loop over the two modes and assert the same message and a non-zero exit in each, which is what your new Python case was reaching for. Asserting !std::filesystem::exists(output) after the run is also possible here, since the test names the output path itself.

Also fold in @adriadam10's size fix: keep range-past-eof at a multiple of 24 (0x108 at 0xFF0), otherwise it exits with Invalid DT_RELASZ value before reaching your check.

2. The rela_bounds expectation — I think it should be updated, deliberately, and named in the body. RelaBoundsTests.cpp has two cases and both go through one helper that asserts "Relocation entry out of bounds":

  case 1   DT_OS_RELA = 0xFFFFFFFFFFFFFFF8, size 24   → offset > file size    → your table check fires
  case 2   DT_OS_RELA = 0x7FF0 (file - 16), size 48   → 48 > 0x8000 - 0x7FF0 → your table check fires

So the helper's expectation is what fails, and both inputs — not just the one the review names — now reach Relocation table is out of bounds first. That is the right message for a table-shaped input, and I could not construct an input that still reaches the entry-level path once the table is validated: a table that passes the size check has every whole entry inside the file by construction. So the honest change is to update that one expectation to the table-level message and say in the description that you are deliberately changing an expectation in #917's test, with the reason. If @adriadam10 would rather keep an entry-level case alive, the person to ask is him — he offered both routes.

I checked the same on the JMPREL side: #1424 landed the matching table check today, so after both, neither relocation reader relies on the per-entry bound for malformed tables.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6062396612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#issuecomment-6062396612). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-08T14:44:10Z. --- Two things from @adriadam10's review are still open, and both have short, concrete answers — here is the pattern, so the port is mechanical rather than a rewrite. **1. The C++ port.** `RelaBoundsTests.cpp` (on `main`, from #917) is the whole template: same fixture, same helpers, same assertions, one file. What you need: ``` file core/relinker/relinker/tests/RelocTableBoundsTests.cpp model core/relinker/relinker/tests/RelaBoundsTests.cpp reg core/relinker/CMakeLists.txt, next to rela_bounds_tests — add_test_executable(reloc_table_bounds_tests ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/RelocTableBoundsTests.cpp) add_test(NAME reloc_table_bounds COMMAND reloc_table_bounds_tests $<TARGET_FILE:relinker>) ``` The includes give you everything: `ElfFixture.hpp` (`Bytes`, `MakeExecutable`, `Write`), `RelinkerProcess.hpp` (`TempDirectory`, `WriteFile`, `RunRelinker` returning `{ExitCode, Output}`). The shape that already works: ```cpp using namespace RelinkerTests; // as RelaBoundsTests.cpp does constexpr std::size_t kRelaTag = 4; // the dynamic slots that file uses constexpr std::size_t kRelaSzTag = 5; constexpr std::int64_t kDtOsRela = 0x6100002f; constexpr std::int64_t kDtRelaSz = 8; Bytes image = MakeExecutable(kCode); Write<std::int64_t>(image, kTagBase + kRelaTag * 16, kDtOsRela); Write<std::uint64_t>(image, kTagBase + kRelaTag * 16 + 8, 0x2000); // the empty-table case Write<std::int64_t>(image, kTagBase + kRelaSzTag * 16, kDtRelaSz); Write<std::uint64_t>(image, kTagBase + kRelaSzTag * 16 + 8, 0); // size 0 ``` Two things that make this cheaper than the Python version: - **It carries the tag indices with it.** `RelaBoundsTests.cpp` writes the OS RELA pair at slots 4 and 5 of the C++ fixture's dynamic array; your Python fixture builds its own tag list, so the indices are not portable. Copy the C++ constants, not the Python list. - **Both modes come free.** `MakeExecutable` already declares `2 + kSpareProgramHeaders` program headers (`ElfFixture.hpp:20,60,65`), so the same image reaches the converter under `--to-intel` as well as `--windows` — loop over the two modes and assert the same message and a non-zero exit in each, which is what your new Python case was reaching for. Asserting `!std::filesystem::exists(output)` after the run is also possible here, since the test names the output path itself. Also fold in @adriadam10's size fix: keep `range-past-eof` at a multiple of 24 (`0x108` at `0xFF0`), otherwise it exits with `Invalid DT_RELASZ value` before reaching your check. **2. The `rela_bounds` expectation — I think it should be updated, deliberately, and named in the body.** `RelaBoundsTests.cpp` has **two** cases and both go through one helper that asserts `"Relocation entry out of bounds"`: ``` case 1 DT_OS_RELA = 0xFFFFFFFFFFFFFFF8, size 24 → offset > file size → your table check fires case 2 DT_OS_RELA = 0x7FF0 (file - 16), size 48 → 48 > 0x8000 - 0x7FF0 → your table check fires ``` So the helper's expectation is what fails, and both inputs — not just the one the review names — now reach `Relocation table is out of bounds` first. That is the right message for a table-shaped input, and I could not construct an input that still reaches the entry-level path once the table is validated: a table that passes the size check has every whole entry inside the file by construction. So the honest change is to update that one expectation to the table-level message and say in the description that you are deliberately changing an expectation in #917's test, with the reason. If @adriadam10 would rather keep an entry-level case alive, the person to ask is him — he offered both routes. I checked the same on the JMPREL side: #1424 landed the matching table check today, so after both, neither relocation reader relies on the per-entry bound for malformed tables. Written with AI assistance.
MarcZX10 commented 2026-10-09 04:41:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T04:41:08Z.


I checked the current CI failure on head 4da534fed782d12444f4c3f016e2b333dde15438. The Linux job stops before the build in tools/check_test_registration.py with:

error: guest_formatting_tests is run by ctest now; remove it from KNOWN_UNRUN

This looks like main drift rather than a relocation-test failure: guest_formatting_tests is now registered with CTest, but remains in the checker’s stale KNOWN_UNRUN list on this branch. Rebasing onto current main and removing that exception should let Linux CI proceed. The current Windows job, all three relinker jobs, Conventions and Progress pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074399058 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#issuecomment-6074399058). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T04:41:08Z. --- I checked the current CI failure on head `4da534fed782d12444f4c3f016e2b333dde15438`. The Linux job stops before the build in `tools/check_test_registration.py` with: ``` error: guest_formatting_tests is run by ctest now; remove it from KNOWN_UNRUN ``` This looks like `main` drift rather than a relocation-test failure: `guest_formatting_tests` is now registered with CTest, but remains in the checker’s stale `KNOWN_UNRUN` list on this branch. Rebasing onto current `main` and removing that exception should let Linux CI proceed. The current Windows job, all three relinker jobs, Conventions and Progress pass.
Dextroid17 commented 2026-10-09 11:23:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T11:23:04Z.


Verified from here, and your diagnosis is right. On upstream/main there is no longer a guest_formatting_tests line in tools/check_test_registration.py, and the test is registered (core/libs/prx/libc/CMakeLists.txt:245). So the

error: guest_formatting_tests is run by ctest now; remove it from KNOWN_UNRUN

you are seeing is the drift you describe — the stale exception was dropped upstream after your base — and a rebase plus deleting that local entry is the whole fix. Nothing about the DT_RELA change is implicated.

Worth noting the checker is earning its keep here: it caught a stale exception rather than a missing registration, which is the same rule from the other side.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079880679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#issuecomment-6079880679). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T11:23:04Z. --- Verified from here, and your diagnosis is right. On `upstream/main` there is no longer a `guest_formatting_tests` line in `tools/check_test_registration.py`, and the test is registered (`core/libs/prx/libc/CMakeLists.txt:245`). So the ``` error: guest_formatting_tests is run by ctest now; remove it from KNOWN_UNRUN ``` you are seeing is the drift you describe — the stale exception was dropped upstream after your base — and a rebase plus deleting that local entry is the whole fix. Nothing about the DT_RELA change is implicated. Worth noting the checker is earning its keep here: it caught a stale *exception* rather than a missing registration, which is the same rule from the other side. Written with AI assistance.
adriadam10 commented 2026-10-09 23:29:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:29:09Z.

Review: APPROVED


Checked on a Linux build merged onto current main: relinker ctest scope 42/42 passes. Reverting only the RelinkerPipeline.cpp guard makes both reloc_table_bounds and rela_bounds fail; with it they pass. The rela_bounds expectation change is correct (the table guard now answers both cases before any entry is read).

The branch conflicted with main only in core/relinker/CMakeLists.txt (next to dynamic_table_bounds); I rebased it keeping both entries. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476314000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1446#pullrequestreview-5476314000). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:29:09Z. **Review:** APPROVED --- Checked on a Linux build merged onto current `main`: relinker ctest scope 42/42 passes. Reverting only the `RelinkerPipeline.cpp` guard makes both `reloc_table_bounds` and `rela_bounds` fail; with it they pass. The `rela_bounds` expectation change is correct (the table guard now answers both cases before any entry is read). The branch conflicted with `main` only in `core/relinker/CMakeLists.txt` (next to `dynamic_table_bounds`); I rebased it keeping both entries. Merging once CI is green.
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!1446
No description provided.