test(relinker): bound input_magic's large input with ASan's allocation cap #9711

Merged
milescoviello merged 1 commit from upstream-pr/9711 into main 2026-10-26 10:35:01 +00:00
milescoviello commented 2026-10-22 09:30:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T09:30:04Z.


What

input_magic fails on every ANYPS5_ENABLE_ASAN build. Its large-input case runs the relinker under a 512 MiB RLIMIT_AS, to show that an 8 GiB non-ELF input is rejected before the relinker allocates it (#8685, #8689). An ASan relinker can't start under that limit:

ERROR: AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes at address 0x02008fff7000 (errno: 12)

That is ASan's own shadow reservation at startup, about 14 TiB of address space. It fails with ENOMEM, and the process dies before it reads anything.

How

  • Under ASan, input_magic gets max_allocation_size_mb=512 through add_asan_test_options, as other tests get their ASan options.
  • When that cap is in ASAN_OPTIONS, the test runs the large-input case without the address-space limit. ASan then refuses an allocation of the whole input, which ends the conversion as the limit does. The shadow reservation isn't an allocation, so the cap leaves it alone.
  • Other builds keep RLIMIT_AS, unchanged.

Tested

  • Rebased onto main 137a8fab89 as e649117dbc (commit unchanged, git range-diff): the 4 tests matching input_magic|^relinker pass 3 of 3 (Linux, Ubuntu 26.04.1, GCC 15.2, Release).
  • Review run by @lulebo (review) on caf4900230 merged onto main dc9f1ef656, WSL 2 Ubuntu 26.04, GCC 15.2.0, relinker-only builds: main fails input_magic under ASan (AddressSanitizer failed to allocate 0xdfff0001000 ... (errno: 12)) and passes in Release; with this PR it passes 3 of 3 in both, and the relinker suite passes 248 of 248 in each. With #8689's prefix check removed, input_magic fails in both builds.

Rebased onto main 093149c5bd as caf4900230, with no conflicts; git range-diff shows the commit unchanged. On that head, input_magic passes 3 of 3 in the ASan build, and 3 of 3 in the default Release build.

Ubuntu 26.04.1, GCC 15.2, on main 7e2ba73e4c, ANYPS5_ENABLE_ASAN=ON (RelWithDebInfo):

  • main: input_magic fails with the shadow error above.
  • With this change: it passes 3 of 3 (--repeat until-fail:3).
  • The case still catches the regression it was written for. With #8689's ReadPrefix(...).ValidateMagic() line removed from core/relinker/main.cpp, the relinker reads the whole file first, ASan refuses the 8 GiB allocation, and input_magic fails.
  • Without ASan (ASAN_OPTIONS unset), the changed script passes against a default Release relinker, through the RLIMIT_AS path as before.
  • tools/check_conventions.py --base upstream/main passes. The overlap scan lists only PRs that conflict with main and touch core/relinker/CMakeLists.txt elsewhere.

This was one of five failures in a full ASan run of the CPU-side suites on main d6eafa54d0 (1161 tests). Three others are already covered: #9236, #9238 and #9240. The fifth, the atrac9_gradient link, is #9710.

Not tested: macOS and Windows (the case is Linux-only).

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: none needed (relinker test only)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4965180637 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9711). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-22T09:30:04Z. --- ### What `input_magic` fails on every `ANYPS5_ENABLE_ASAN` build. Its large-input case runs the relinker under a 512 MiB `RLIMIT_AS`, to show that an 8 GiB non-ELF input is rejected before the relinker allocates it (#8685, #8689). An ASan relinker can't start under that limit: ``` ERROR: AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes at address 0x02008fff7000 (errno: 12) ``` That is ASan's own shadow reservation at startup, about 14 TiB of address space. It fails with `ENOMEM`, and the process dies before it reads anything. ### How - Under ASan, `input_magic` gets `max_allocation_size_mb=512` through `add_asan_test_options`, as other tests get their ASan options. - When that cap is in `ASAN_OPTIONS`, the test runs the large-input case without the address-space limit. ASan then refuses an allocation of the whole input, which ends the conversion as the limit does. The shadow reservation isn't an allocation, so the cap leaves it alone. - Other builds keep `RLIMIT_AS`, unchanged. ### Tested - **Rebased** onto `main` 137a8fab89 as `e649117dbc` (commit unchanged, `git range-diff`): the 4 tests matching `input_magic|^relinker` pass 3 of 3 (Linux, Ubuntu 26.04.1, GCC 15.2, Release). - **Review run by @lulebo** ([review](https://github.com/boykopovar/AnyPS5/pull/9711#pullrequestreview-5639098365)) on `caf4900230` merged onto `main` dc9f1ef656, WSL 2 Ubuntu 26.04, GCC 15.2.0, relinker-only builds: `main` fails `input_magic` under ASan (`AddressSanitizer failed to allocate 0xdfff0001000 ... (errno: 12)`) and passes in Release; with this PR it passes 3 of 3 in both, and the relinker suite passes 248 of 248 in each. With #8689's prefix check removed, `input_magic` fails in both builds. **Rebased** onto `main` 093149c5bd as `caf4900230`, with no conflicts; `git range-diff` shows the commit unchanged. On that head, `input_magic` passes 3 of 3 in the ASan build, and 3 of 3 in the default Release build. Ubuntu 26.04.1, GCC 15.2, on `main` 7e2ba73e4c, `ANYPS5_ENABLE_ASAN=ON` (RelWithDebInfo): - `main`: `input_magic` fails with the shadow error above. - With this change: it passes 3 of 3 (`--repeat until-fail:3`). - The case still catches the regression it was written for. With #8689's `ReadPrefix(...).ValidateMagic()` line removed from `core/relinker/main.cpp`, the relinker reads the whole file first, ASan refuses the 8 GiB allocation, and `input_magic` fails. - Without ASan (`ASAN_OPTIONS` unset), the changed script passes against a default Release relinker, through the `RLIMIT_AS` path as before. - `tools/check_conventions.py --base upstream/main` passes. The overlap scan lists only PRs that conflict with `main` and touch `core/relinker/CMakeLists.txt` elsewhere. This was one of five failures in a full ASan run of the CPU-side suites on `main` d6eafa54d0 (1161 tests). Three others are already covered: #9236, #9238 and #9240. The fifth, the `atrac9_gradient` link, is #9710. Not tested: macOS and Windows (the case is Linux-only). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: none needed (relinker test only) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-22 12:08:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:08:21Z.

Review: COMMENTED


Reviewed exact head 54d65ae8fe1e3bdb3d23a0dabc9d1546a9d2e5ec. The change preserves the 512 MiB address-space regression check for ordinary builds and switches only the ASan case to the allocator-cap path, which avoids constraining ASan’s shadow reservation. The regression still checks the invalid-magic diagnostic and that no output is written. Current conventions and diff checks pass; GitHub reports the relinker matrix on Ubuntu, Windows, macOS, x86_64 macOS, and ASan passing. I could not rerun locally because there is no configured build tree and the filesystem is full. One contribution-rule follow-up: the branch is 13 commits behind current main (base 7e2ba73e4c, current 8b3a6ba88d). Please update it and confirm the focused relinker/ASan test on current main; I found no code-level defect.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5613880083 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9711#pullrequestreview-5613880083). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T12:08:21Z. **Review:** COMMENTED --- Reviewed exact head 54d65ae8fe1e3bdb3d23a0dabc9d1546a9d2e5ec. The change preserves the 512 MiB address-space regression check for ordinary builds and switches only the ASan case to the allocator-cap path, which avoids constraining ASan’s shadow reservation. The regression still checks the invalid-magic diagnostic and that no output is written. Current conventions and diff checks pass; GitHub reports the relinker matrix on Ubuntu, Windows, macOS, x86_64 macOS, and ASan passing. I could not rerun locally because there is no configured build tree and the filesystem is full. One contribution-rule follow-up: the branch is 13 commits behind current main (base `7e2ba73e4c`, current `8b3a6ba88d`). Please update it and confirm the focused relinker/ASan test on current main; I found no code-level defect.
milescoviello commented 2026-10-22 12:29:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T12:29:59Z.


@MarcZX10 rebased onto main 8b3a6ba88d as 1bd662ac48, with no conflicts; the commit is unchanged. On that head, input_magic passes 3 of 3 in the ASan build (the allocation-cap path) and 3 of 3 in the default Release build (the RLIMIT_AS path). Tested names the head.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340771994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9711#issuecomment-6340771994). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-22T12:29:59Z. --- @MarcZX10 rebased onto `main` 8b3a6ba88d as `1bd662ac48`, with no conflicts; the commit is unchanged. On that head, `input_magic` passes 3 of 3 in the ASan build (the allocation-cap path) and 3 of 3 in the default Release build (the `RLIMIT_AS` path). Tested names the head. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-22 15:43:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T15:43:10Z.

Review: DISMISSED


I reviewed exact head 1bd662ac483277ad764f2e60ba8fbaf50331fa91. The test correctly keeps RLIMIT_AS for normal runs and disables it only when the ASan allocation cap is present; CMake appends the cap to ASAN_OPTIONS for the test, which the child relinker inherits. I found no code-level defect.

Checks:

  • Python syntax compilation passed for the exact-head test_input_magic.py.
  • git diff --check and tools/check_conventions.py against current main passed.
  • Hosted Ubuntu, Windows, macOS, macOS x86_64, and relinker-asan jobs all pass, as do eligibility/conventions/labels. Product Linux/Windows jobs are not applicable to this relinker-only change.
  • I did not rerun the integration test locally because this workspace has no relinker build tree/executable. The hosted runs are exact-head evidence.

Please refresh to current main and rerun input_magic, including the ASan configuration. This branch is 50 commits behind current main; the changed files have not changed since the branch’s last sync, but CONTRIBUTING.md requires branches to stay current.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5616896074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9711#pullrequestreview-5616896074). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T15:43:10Z. **Review:** DISMISSED --- I reviewed exact head 1bd662ac483277ad764f2e60ba8fbaf50331fa91. The test correctly keeps RLIMIT_AS for normal runs and disables it only when the ASan allocation cap is present; CMake appends the cap to ASAN_OPTIONS for the test, which the child relinker inherits. I found no code-level defect. Checks: - Python syntax compilation passed for the exact-head test_input_magic.py. - git diff --check and tools/check_conventions.py against current main passed. - Hosted Ubuntu, Windows, macOS, macOS x86_64, and relinker-asan jobs all pass, as do eligibility/conventions/labels. Product Linux/Windows jobs are not applicable to this relinker-only change. - I did not rerun the integration test locally because this workspace has no relinker build tree/executable. The hosted runs are exact-head evidence. Please refresh to current main and rerun input_magic, including the ASan configuration. This branch is 50 commits behind current main; the changed files have not changed since the branch’s last sync, but CONTRIBUTING.md requires branches to stay current.
lulebo commented 2026-10-24 17:12:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by lulebo on 2026-10-24T17:12:09Z.

Review: COMMENTED


Reviewed head caf4900230 merged onto main dc9f1ef656 (2026-10-24). The head is 2,166 commits behind and merges without conflicts.

Environment: WSL 2 Ubuntu 26.04 x86-64, GCC 15.2.0, CMake 4.2.3, Ninja 1.13.2, Python 3.14.4. Relinker-only builds: ASan configured as the relinker-asan job (-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++ -DANYPS5_RELINKER_ONLY=ON -DANYPS5_ENABLE_ASAN=ON -DBUILD_TESTING=ON), and Release.

Results

  • main alone: input_magic fails in the ASan build with AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes at address 0x02008fff7000 (errno: 12) and passes in Release.
  • With this PR: input_magic passes 3 of 3 in both builds (--repeat until-fail:3). The whole relinker suite passes, 248 of 248 under ASan and 248 of 248 in Release.
  • Red/green on the regression the test guards: with #8689's prefix check removed from core/relinker/main.cpp:44 (Relinker::ElfReader(fileReader.ReadPrefix(inputPath, 0x40)).ValidateMagic();), input_magic fails in both builds. Under ASan the 8 GiB read is refused (requested allocation size 0x200000000, allocation-size-too-big); in Release it ends in std::bad_alloc under the 512 MiB RLIMIT_AS. Restored, both pass.

Not checked: Clang's ASan; macOS and Windows (the case is Linux-only).

No issues found. On MarcZX10's refresh request: the head is behind main again, but merges onto current main without conflicts and passes as above.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639098365 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9711#pullrequestreview-5639098365). Originally posted by [lulebo](https://github.com/lulebo) on 2026-10-24T17:12:09Z. **Review:** COMMENTED --- Reviewed head caf4900230 merged onto `main` dc9f1ef656 (2026-10-24). The head is 2,166 commits behind and merges without conflicts. **Environment:** WSL 2 Ubuntu 26.04 x86-64, GCC 15.2.0, CMake 4.2.3, Ninja 1.13.2, Python 3.14.4. Relinker-only builds: ASan configured as the `relinker-asan` job (`-DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++ -DANYPS5_RELINKER_ONLY=ON -DANYPS5_ENABLE_ASAN=ON -DBUILD_TESTING=ON`), and Release. **Results** - `main` alone: `input_magic` fails in the ASan build with `AddressSanitizer failed to allocate 0xdfff0001000 (15392894357504) bytes at address 0x02008fff7000 (errno: 12)` and passes in Release. - With this PR: `input_magic` passes 3 of 3 in both builds (`--repeat until-fail:3`). The whole relinker suite passes, 248 of 248 under ASan and 248 of 248 in Release. - Red/green on the regression the test guards: with #8689's prefix check removed from `core/relinker/main.cpp:44` (`Relinker::ElfReader(fileReader.ReadPrefix(inputPath, 0x40)).ValidateMagic();`), `input_magic` fails in both builds. Under ASan the 8 GiB read is refused (`requested allocation size 0x200000000`, `allocation-size-too-big`); in Release it ends in `std::bad_alloc` under the 512 MiB `RLIMIT_AS`. Restored, both pass. **Not checked:** Clang's ASan; macOS and Windows (the case is Linux-only). No issues found. On MarcZX10's refresh request: the head is behind `main` again, but merges onto current `main` without conflicts and passes as above. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
THEMANnt commented 2026-10-25 04:57:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T04:57:36Z.

Review: APPROVED


Reviewed head e649117dbcbe75f51002f4fc357c81c6cbbe823b against author merge base 137a8fab8984506ec9359dbfc2651bc367e0d381: approve. No actionable findings in the test harness changes.

The new test-specific ASAN_OPTIONS allocation cap avoids applying RLIMIT_AS to ASan's large virtual address reservation. The ordinary Linux path retains the existing address-space/core limits, diagnostic assertion and timeout. Checked the root add_asan_test_options helper and its conditional environment modification.

Validation: four cases executing the extracted branch selection verified that preexec_fn remains the limiter without the cap and becomes None when the cap is present. A real CMake/CTest fixture using the exact helper and added registration verified propagation as detect_leaks=0:max_allocation_size_mb=512 (1 passed, zero skipped). Conventions, whitespace and registration passed. Hosted Ubuntu job 120939602001 explicitly passed input_magic on the PR merge checkout. The successful hosted ASan job 120939602049 ran only 33 tls_function_coverage tests, so it does not establish an ASan input_magic pass. No Linux/ASan executable or 8-GiB input was run locally; approval covers the reviewed harness logic and option wiring, with that runtime limitation explicit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641629853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9711#pullrequestreview-5641629853). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-25T04:57:36Z. **Review:** APPROVED --- Reviewed head `e649117dbcbe75f51002f4fc357c81c6cbbe823b` against author merge base `137a8fab8984506ec9359dbfc2651bc367e0d381`: approve. No actionable findings in the test harness changes. The new test-specific ASAN_OPTIONS allocation cap avoids applying RLIMIT_AS to ASan's large virtual address reservation. The ordinary Linux path retains the existing address-space/core limits, diagnostic assertion and timeout. Checked the root add_asan_test_options helper and its conditional environment modification. Validation: four cases executing the extracted branch selection verified that preexec_fn remains the limiter without the cap and becomes None when the cap is present. A real CMake/CTest fixture using the exact helper and added registration verified propagation as `detect_leaks=0:max_allocation_size_mb=512` (1 passed, zero skipped). Conventions, whitespace and registration passed. Hosted Ubuntu job 120939602001 explicitly passed input_magic on the PR merge checkout. The successful hosted ASan job 120939602049 ran only 33 tls_function_coverage tests, so it does **not** establish an ASan input_magic pass. No Linux/ASan executable or 8-GiB input was run locally; approval covers the reviewed harness logic and option wiring, with that runtime limitation explicit.
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!9711
No description provided.