PE loader: relocation targets outside the image fail the load #291
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!291
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-291"
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?
@honestlyBroke on GitHub · 2026-11-23 22:28 UTC · original
honestlyBroke:pe-loader-reloc-bounds→main· +39 −0 · 1 files · 1 commits · openHardening, not a playability fix: no title is known to hit this path.
map_imagepatchedbase + rvafor every relocation without checking the target against the mapping. The entries come from the file, so a target pastSizeOfImage, or a DIR64 whose 8 bytes straddle its end, wrote outside the image. #178 made the RVA arithmetic overflow-safe but did not bound the targets. The check is in the loader, not inPe::relocations, because that also reads file-layout images and has no mapping size.Part of #106.
What is in it
crates/xcl/src/loader.rs: before patching, the target plus its width (8 for DIR64, 4 for HIGHLOW) must fit inSizeOfImage. Otherwise the load fails with "relocation at … outside the image" and the mapping is freed.crates/xcl/src/loader.rs(tests):relocations_outside_the_image_are_errorsusestiny_dllwith its preferred address taken. Covers a target past the end, a DIR64 straddling the end, and a control target inside the image that is still relocated by the right delta.Tested
cargo test --workspace -- --test-threads=4: 652 passed, 0 failed, 40 ignored. SKIPPED GPU tests:gpu_wave32_program_in_wave64_hardware,gpu_geometry_wave32_prefix_count_over_a_mask(no wave64)Regression run
Not run yet. I'll add both
xcl-smokeblocks (main and this PR's head) and mark the PR ready once I have a title folder to run against. Until then it stays a draft.Not tested
scripts/smoke.ps1regression run on a real title (see above)AI use
@mastrr9 on GitHub · 2026-11-23 22:52 UTC · original
Independent static code audit of
227e1a01e(code inspection only —cargo testnot run on macOS; no game files):Summary: Looks solid
r.rva as usize + width > sizecatches both past-end targets and straddlingDIR64(8 B) /HIGHLOW(4 B) writes before dereferencing, and cleans up the mapping viafail(...).Minor non-blocking notes
(r.rva as usize).checked_add(width).is_none_or(|end| end > size)makes overflow-safety explicit (already safe on 64-bit sincer.rvaisu32).loader.rs:121, 125):(v as i64 + delta)can panic on signed overflow in debug builds if hardening against crafted relocations (wrapping_addavoids that).(AI-assisted)
@MesshM on GitHub · 2026-11-24 04:27 UTC · original
Test run of
c1776d808d0490f4cda7b3e0e3c90c2c24435cdfon AMD RDNA4. I merged it onto currentmain64b3f35locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 702 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 661 passed, 0 failed, 21 ignoredSKIPPED;relocations_outside_the_image_are_errorspasses.Review: A relocation whose target plus width (8 for DIR64, 4 for HIGHLOW) goes past
SizeOfImagenow fails the load instead of writing outside the mapping;ABSOLUTEentries have width 0 and pass as before. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@einfachama on GitHub · 2026-11-24 11:46 UTC · original
Regression run on a retail title for #291, since Not tested lists it: head
c1776d808d0490f4cda7b3e0e3c90c2c24435cdfmerged ontomaind208e14(clean merge, local merge commitb0de7d3). Normal loads are unchanged: my retail title loads its 8 images (6 of them relocated) exactly as onmainand runs at its first menu as before.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4: 705 passed, 0 failed, 41 ignored (maind208e14in its clean run: 704 / 0 / 41). SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.scripts/smoke.ps1 -Seconds 60, unattended, the learned window in both runs. XCL's log shows the same image loads on both (8 loaded, 6 relocated, no relocation error):The second block is the local merge onto
main, not the PR's head commit, so it can't stand in for the PR's own Regression run (pr_check.pywants the head commit there). It shows that real loads are unchanged here.Not tested
AI use
@Toons29 on GitHub · 2026-11-25 02:53 UTC · original
Regression run of
c1776d80on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 90 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.@DavidM1911 on GitHub · 2026-11-25 14:43 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.