xmem: use saturating_add for view end bounds in aliases (fixes #2413) #2421
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2421
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@pushkarreddyy on GitHub · 2026-11-25 13:12 UTC · original
pushkarreddyy:fix/xmem-aliases-saturating-add→main· +27 −2 · 1 files · 1 commits · closed without mergingFixes #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.@pushkarreddyy on GitHub · 2026-11-25 13:36 UTC · original
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!@kotekompotek on GitHub · 2026-11-25 13:53 UTC · original
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.@dpalacios69 on GitHub · 2026-11-25 14:09 UTC · original
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.
@pushkarreddyy on GitHub · 2026-11-25 14:18 UTC · original
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)
@Marvisak on GitHub · 2026-11-25 15:32 UTC · original
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
@DenRakEiw on GitHub · 2026-11-25 13:18 UTC · original · approved these changes
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).
@catminou4 on GitHub · 2026-11-25 13:19 UTC · original · reviewed
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.
@pushkarreddyy on GitHub · 2026-11-26 15:19 UTC · original
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