xmem: use saturating_add for view end bounds in aliases (fixes #2413) #2419
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2421"
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 Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T13:12:20Z.
Fixes #2413.
Root Cause
In
crates/victory-hle/src/modules/xmem.rs(aliases),endis computed safely withat.saturating_add(len), but the preceding-view filter (*base + size > at) and range clamp (end.min(base + size)) used unchecked addition, which can overflow if a view'sbase + sizereachesusize::MAX.Implementation Details
*base + sizeandbase + sizeincrates/victory-hle/src/modules/xmem.rs(aliases) to usebase.saturating_add(*size).Verification
aliases_handles_saturating_range_boundsunit test incrates/victory-hle/src/modules/xmem.rsexercisingaliasesnearusize::MAX.check(workspace build, clippy-D warnings, and tests) is green.Scope & Limitations
aliasesare changed; virtual memory and physical-page behavior are unchanged.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:18:42Z.
Review: APPROVED
Verified against
origin/main(940d32f):saturating_addfor view end bounds inxmem::aliasescleanly prevents overflow on malformed/near-max ranges (#2413).cargo test -p victory-hle xmem::: 11/11 passed (includingaliases_handles_saturating_range_bounds).cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:31Z.
Review: COMMENTED
xmem: saturating_add for view end bounds in aliases. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Correct hardening.
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T13:36:25Z.
Hi @Marvisak — this PR resolves #2413 (using
saturating_addforbase + sizeview bounds inxmem::aliases), with unit tests and CI (check) passing. Ready for review and merge whenever convenient!Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T13:53:21Z.
Reviewed:
endwas alreadysaturating_add, and this covers the two remainingbase + sizespots — consistent. Theusize::MAX - PAGE + 1test hits the path that would panic in debug builds.Imported from Marvisak/VIctory. Originally posted by dpalacios69 on 2026-11-25T14:09:02Z.
Static read of
d28cb1dagainstmain940d32f(not run:victory-hleis Windows-only).On the earlier comment that the
usize::MAX - PAGE + 1test "hits the path that would panic in debug builds": as far as I can tell it does not reach the changed arithmetic.endwas alreadyat.saturating_add(len), andbase + size(xmem.rs:412,:417) can only overflow when a view inphysical().viewshasbase + size > usize::MAX. The test inserts no view, sorange(..=at).next_back()finds nothing (or, if another test left a small view in the sharedPHYSICAL,base + sizeis far from overflowing), andstartsoverat + 1..endis empty. Soaliases_handles_saturating_range_boundsshould pass onmaintoo, and the approvals above ran it only with the fix applied.A test that fails before the patch would insert a view near the top, e.g. base
usize::MAX - PAGE + 1with a size of2 * PAGE, callaliaseson that range, and assert the result. Could someone on Windows confirm what the current test does with the twosaturating_addlines reverted?AI-assisted analysis.
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-25T14:18:57Z.
Thank you @dpalacios69 for catching that test gap! Updated the test in
c315049(aliases_handles_saturating_range_bounds) to allocate a page, insert a view intophysical().viewsatusize::MAX - PAGE + 1with size2 * PAGE, and callaliases(top + 1, PAGE, &mut out)so bothbase.saturating_add(*size)paths are directly exercised.Testers on Windows 10/11 and Wine/Proton setups we haven't tested yet are welcome to verify this fix.
AI-assisted: yes (Gemini 4 Neon)
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:32:18Z.
Automated triage for the maintainers.
Proposed close. This changes
*base + sizeandbase + sizeincrates/victory-hle/src/modules/xmem.rsaliasestosaturating_add. The keys ofphysical().viewsare the addresses of title views mapped into the process (views.insert(base, (len, slice))in the mapping path), and theirbase + sizestays inside the user address space, far belowusize::MAX, so the overflow cannot happen. The new test reaches the changed lines only by inserting a view atusize::MAX - PAGE + 1by hand, which xmem never creates. A path through xmem that records a view ending past the top of the address space would change this verdict.This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T15:19:13Z.
Closing this PR after reviewing the triage verification on
main:physical().viewsonly records user-space mapped addresses well belowusize::MAX, sobase + sizeinaliasescannot overflow during realxmemexecution.Thank you for the audit.
AI-assisted: yes (Gemini 4 Neon)
Pull request closed