fix(relinker): guard Windows entry-stub RVA allocations #6204
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6204"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by vrebel11 on 2026-10-15T02:54:05Z.
What
This hardens Windows entry-stub allocation handling. It does not establish a fix for the intermittent GCC crash reported in #5927.
The runtime boundary test alone is not proven to fail against the previous implementation. The separate source-level guard verifies that endpoint checks precede buffer resizing.
Tested
windows_entry_stub_bounds: passed.windows_entry_stub_endpoint_guard: passed.python3 tools/check_conventions.py --base origin/main: passed.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T03:18:08Z.
Review: COMMENTED
Built and tested this on Apple silicon (not Windows), so a few notes.
Machine: Apple M2 Max, macOS 27.2, AppleClang (Xcode 27), CMake 4.4.4 + Ninja.
Head: 0d429424a9c8750a037b12c63248311d3337c16e
Base: origin/main
760ffa6838Build: relinker-only (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), both arm64 and x86_64 (-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3).The PR compiles cleanly on both arches; no macOS-specific issues.
relinker_corealready compilesWindowsEntryStubBuilder.cppon every host, so the hardening builds everywhere.Two things worth flagging:
The new tests are gated behind
if(WIN32), so they never run on the Linux/macOS CI. That is inconsistent with the sibling Windows tests in the same file (windows_icon_resource,entry_stub), which are registered unconditionally and link the same Windows sources intorelinker_core. I removed theif(WIN32)guard locally and both targets built and ran fine on arm64 and x86_64. Registering them unconditionally would give this hardening coverage on the default (non-Windows) CI.The runtime
windows_entry_stub_boundstest does not fail against the previous implementation. With the fix reverted but the test kept, on arm64 it still passes:Only the source-text guard catches the regression; the runtime test passes with and without the fix. This matches your own note. The source-grep guard is also brittle (it matches literal source strings). A runtime case that actually drives the allocation past the signed-32-bit PE RVA boundary / vector capacity and expects the new
RelinkerExceptionwould protect the behavior instead of the source text.Full suite with the fix: arm64 165/165, x86_64 160/165 (the 5 failures are pre-existing on x86_64+Py3.9:
pr_overlap_encoding,pr_overlap_tools,stubgen_stdout_newlines,release_package,linux_fixed_base).Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by vrebel11 on 2026-10-16T22:28:57Z.
Thanks for taking the time to build and test this on both macOS architectures and for the detailed feedback.
I agree with both points. I'll remove the Windows-only test registration guard and work on a runtime regression that fails against the original implementation, rather than relying on the source-text check.
I'll run the relevant tests again and update this PR with the changes. Appreciate the independent verification!
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T17:15:49Z.
Review: CHANGES_REQUESTED
Thanks. The endpoint check before
resizeis reasonable, but the tests don't protect it yet:WindowsEntryStubBoundsTests.cpp: per your own note (and @jotitadev's run)windows_entry_stub_boundspasses without the change, so it pins nothing. Add a case that crosses the 2 GiB limit only because of the new endpoint check (an allocation that starts belowINT32_MAXand ends above it) and expects theRelinkerException; show that it fails onmain.WindowsEntryStubEndpointGuard.cmake: it greps literal source text, so it breaks on any reformat and pins no behaviour. Drop it once the runtime test above fails without the fix.core/relinker/CMakeLists.txt:675: remove theif(WIN32)guard, as you already agreed with @jotitadev; the siblingentry_stubtest is registered unconditionally and the sources build on every host.WindowsEntryStubBoundsTests.cpp:99: add the missing trailing newline and drop the double blank lines.Happy to re-review once pushed.
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T13:49:33Z.
Review: DISMISSED
Reviewed
0d429424a9c8against merge base760ffa6838d0. Changes requested for missing regression coverage of the new allocation-endpoint check.Exercise an allocation that crosses the signed RVA limit. The new runtime test also passes when linked against the unchanged baseline implementation. It therefore does not detect removal of the endpoint check. The source-text guard fails on baseline, but that establishes a textual difference rather than the runtime boundary behavior.
Add an input whose allocation starts below the 2 GiB RVA limit but ends beyond it, assert
RelinkerException, and demonstrate failure against baseline. Replace the brittle source-text guard with that runtime regression. Register these tests outsideif(WIN32)so Linux/macOS exercise the platform-independent builder, consistent with neighboring tests.Validation: Candidate focused tests pass 3/3; baseline entry-stub test passes 1/1. The candidate runtime test linked against baseline also exits 0. These findings concern coverage and CI visibility; no production-check defect is claimed.