XGameRuntime: avoid signed overflow in XUserCompare #1193
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1202"
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-24T13:11:10Z.
XUserComparecomputed(a as isize - b as isize).signum() as i32, which overflows when the pointer difference exceedsisize::MAX—aborting on panic insideextern "system" fnin debug builds and wrapping to the inverted sign in release builds.This replaces the signed subtraction with
(a as usize).cmp(&(b as usize)) as i32.What is in it
crates/xcl/src/hle/xgameruntime/mod.rs: compare handles with(a as usize).cmp(&(b as usize)) as i32inXUserCompare; add unit testxuser_compare_does_not_overflow_pointer_difference(aborted with0xc0000409before the fix).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): 742 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 xuser_compare_does_not_overflow_pointer_difference: 1 passed, 0 failed (panicked/aborted with0xc0000409before the fix)Regression run
main:
PR:
Not tested
AI use
xgameruntime/mod.rs, wrote the fix and regression test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:31:27Z.
Independent verification on current
main384f7f7(branch already contains it — clean).Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.
cargo test -p xcl --lib xuser: 1 passed, 0 failed —xuser_compare_does_not_overflow_pointer_differencecovers the signed-overflow fix.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
upstream-sync referenced this pull request2026-11-25 06:04:27 +00:00
upstream-sync referenced this pull request2026-11-25 16:10:51 +00:00
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-27T21:26:35Z.
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 BBareth on 2026-11-30T23:20:30Z.
merge-check claim
head:
859e6ae0aaImported from ivall/xcl. Originally posted by BBareth on 2026-11-30T23:28:26Z.
merge-check
base:
d0832e614fhead:
859e6ae0aamerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same run: 2890 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The new test
xuser_compare_does_not_overflow_pointer_differenceran and passed.review: no blocking finding; one file (+16/-1), read.
XUserComparecompares the two handles as unsigned addresses (Ordering as i32is -1 / 0 / 1) instead of taking the sign of a signed difference, which overflows when the two values are more thanisize::MAXapart (a panic in a debug build). For any two user-mode addresses the result is the same as before; only values at or above 2^63 change order, and those are not handles XCL gives out.performance: none.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:05:32Z.
Triage (#1607) – head
859e6aeNo open or merged PR changes XUserCompare; main still computes
(a as isize - b as isize).signum(), which overflows (and panics in debug) for handles on either side of 0x8000_0000_0000_0000. The test fails without the fix in a debug build.No problems found in the diff.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T10:17:13Z.
merge-check
base:
1c8b551475head:
859e6ae0aamerge: clean (trial-merge commit e3c74429bc5ea3450ce3d93cf5f7bedcb01b3706, git diff --check clean)
build: cargo build --workspace ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture (43 targets): 2910 passed, 0 failed, 51 ignored (+1 new test vs main baseline). Targeted new test hle::xgameruntime::tests::xuser_compare_does_not_overflow_pointer_difference passed with 0 skips. 28 SKIPPED lines (host environment only: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache (Windows Developer Mode required)).
review: Read the full merged diff (+16/-1 in crates/xcl/src/hle/xgameruntime/mod.rs). Replaces
(a as isize - b as isize).signum() as i32inXUserComparewith(a as usize).cmp(&(b as usize)) as i32, returning -1, 0, or 1 viastd::cmp::Orderingwithout signed subtraction overflow (debug panic) or wraparound sign inversion (release) for handles spanning the high-bit boundary. Unit test covers equal,0x7FFF_FFFF_FFFF_FFFFvs0x8000_0000_0000_0000, and null vsusize::MAX. Exact, minimal, no scope creep or UB.performance: not applicable (Tier 1 — single-line comparison fix in
XUserCompare, off hot rendering/GPU paths).verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by cj-tomlin on 2026-12-02T16:54:00Z.
Test report, head
859e6ae0aaa7ceec963f8c0f7d50978558c52ce4merged ontomain5eaadb54c14e0fc29597b2a1689d7dbd83491303(clean, merge94aef89d).cargo build --workspace: ok.cargo test --workspace --no-fail-fast -- --test-threads=4: 2975 passed, 0 failed, 52 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll), the same 27 as plainmain(2974 passed, 0 failed, 52 ignored) on this machine.mainhere:two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(#3441) andpso_async::used_tests::retained_failed_demand_observes_another_binds_successful_retry(#3180). The numbers above are from the rerun.xuser_compare_does_not_overflow_pointer_differencepasses, and fails withattempt to subtract with overflowwhen I putmain's(a as isize - b as isize).signum()back into the merged tree.Diff read (+16/-1,
xgameruntime/mod.rs), CPU only.Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.