PE loader: use wrapping u64 delta and clamp VirtualProtect extents in map_image_ex #1406
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1416"
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 ivall/xcl. Originally posted by b3IKK on 2026-11-24T15:44:27Z.
Fixes two overflow and bounds bugs in
crates/xcl/src/loader.rs:map_image_excomputedlet delta = base as i64 - pe.image_base as i64and applied(v as i64 + delta), which panicked with signed overflow whenpe.image_basewas near0x8000_0000_0000_0000. Using unsignedwrapping_sub/wrapping_addhandles every 64-bit relocation and TLS base adjustment cleanly.pe.size_of_headersand((s.mapped_size() as usize) + 0xFFF) & !0xFFFtoVirtualProtect, allowing oversized headers or section extents to alter page protections past[base, base + size). Step 2 also used uncheckedsrc + raw/s.va + raw.This uses wrapping
u64arithmetic fordelta, clamps header and sectionVirtualProtectranges to[0, size)viasection_protect_range(), and uses checked addition in section copy.What is in it
crates/xcl/src/loader.rs: switchdeltato wrappingu64arithmetic; addsection_protect_range()and clampVirtualProtectextents tosize; usechecked_addfor section copy bounds; add unit testsrelocates_high_image_base_without_signed_overflow(verified panicking before the fix) andsection_protect_range_clamps_to_image_size.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 753 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib loader::tests: 4 passed, 0 failed (relocates_high_image_base_without_signed_overflowpanicked with signed subtraction overflow before the fix)Regression run
main:
PR:
Not tested
AI use
loader.rs, wrote the fixes and unit tests, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:56:14Z.
Full-suite run, since this PR has no test report yet. Tested exact head
eb5c719(on its base930e8b4).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.relocates_high_image_base_without_signed_overflow,section_protect_range_clamps_to_image_size.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T17:13:09Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (One parallel run showed a single flaky failure; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-25T11:58:55Z.
Test report for head
eb5c719as pushed (not merged onto currentmain) – NVIDIA, wave32.Tested
.\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 753 passed, 0 failed, 41 ignoredrelocates_high_image_base_without_signed_overflowandsection_protect_range_clamps_to_image_sizeran and passedXCL_SAMPLE_*data set (game-data tests not run)Not tested
mainAI use
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:42:13Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:40:30Z.
Triage (#1607) – head
eb5c719Not on main: main's
map_image_exstill computesdeltaasbase as i64 - pe.image_base as i64and protectss.va + round_up(mapped_size)without clamping. #1367 also clamps the sectionVirtualProtectlength to the image (one hunk overlaps), but it does not change the signed delta or the overflow-checked section copy, so the two are not the same change.No problems found in the diff; the DIR64 test with an image base of 0x8000_0000_0000_0000 exercises the overflow the old
i64arithmetic hit.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.