xmem: use saturating_add for view end bounds in aliases (fixes #2413) #2421

Closed
github-bot wants to merge 1 commit from github-bot/gh-2421 into main AGit
Owner

@⁠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 merging

Fixes #2413.

Root Cause

In crates/victory-hle/src/modules/xmem.rs (aliases), end is computed safely with at.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's base + size reaches usize::MAX.

Implementation Details

  • Updated both *base + size and base + size in crates/victory-hle/src/modules/xmem.rs (aliases) to use base.saturating_add(*size).

Verification

  • Added aliases_handles_saturating_range_bounds unit test in crates/victory-hle/src/modules/xmem.rs exercising aliases near usize::MAX.
  • CI check (workspace build, clippy -D warnings, and tests) is green.

Scope & Limitations

  • Only the two unchecked view-end additions in aliases are changed; virtual memory and physical-page behavior are unchanged.
  • No title files or proprietary assets were used.
**@⁠pushkarreddyy** on GitHub · 2026-11-25 13:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421) `pushkarreddyy:fix/xmem-aliases-saturating-add` → `main` · +27 −2 · 1 files · 1 commits · closed without merging Fixes #2413. ### Root Cause In `crates/victory-hle/src/modules/xmem.rs` (`aliases`), `end` is computed safely with `at.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's `base + size` reaches `usize::MAX`. ### Implementation Details - Updated both `*base + size` and `base + size` in `crates/victory-hle/src/modules/xmem.rs` (`aliases`) to use `base.saturating_add(*size)`. ### Verification - Added `aliases_handles_saturating_range_bounds` unit test in `crates/victory-hle/src/modules/xmem.rs` exercising `aliases` near `usize::MAX`. - CI `check` (workspace build, clippy `-D warnings`, and tests) is green. ### Scope & Limitations - Only the two unchecked view-end additions in `aliases` are changed; virtual memory and physical-page behavior are unchanged. - No title files or proprietary assets were used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:19 +00:00
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-25 13:36 UTC · original

Hi @⁠Marvisak — this PR resolves #2413 (using saturating_add for base + size view bounds in xmem::aliases), with unit tests and CI (check) passing. Ready for review and merge whenever convenient!

**@⁠pushkarreddyy** on GitHub · 2026-11-25 13:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#issuecomment-7164022797) Hi @⁠Marvisak — this PR resolves #2413 (using `saturating_add` for `base + size` view bounds in `xmem::aliases`), with unit tests and CI (`check`) passing. Ready for review and merge whenever convenient!
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 13:53 UTC · original

Reviewed: end was already saturating_add, and this covers the two remaining base + size spots — consistent. The usize::MAX - PAGE + 1 test hits the path that would panic in debug builds.

**@⁠kotekompotek** on GitHub · 2026-11-25 13:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#issuecomment-7164436943) Reviewed: `end` was already `saturating_add`, and this covers the two remaining `base + size` spots — consistent. The `usize::MAX - PAGE + 1` test hits the path that would panic in debug builds.
Author
Owner

@⁠dpalacios69 on GitHub · 2026-11-25 14:09 UTC · original

Static read of d28cb1d against main 940d32f (not run: victory-hle is Windows-only).

On the earlier comment that the usize::MAX - PAGE + 1 test "hits the path that would panic in debug builds": as far as I can tell it does not reach the changed arithmetic. end was already at.saturating_add(len), and base + size (xmem.rs:412, :417) can only overflow when a view in physical().views has base + size > usize::MAX. The test inserts no view, so range(..=at).next_back() finds nothing (or, if another test left a small view in the shared PHYSICAL, base + size is far from overflowing), and starts over at + 1..end is empty. So aliases_handles_saturating_range_bounds should pass on main too, 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 + 1 with a size of 2 * PAGE, call aliases on that range, and assert the result. Could someone on Windows confirm what the current test does with the two saturating_add lines reverted?

AI-assisted analysis.

**@⁠dpalacios69** on GitHub · 2026-11-25 14:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#issuecomment-7164833688) Static read of `d28cb1d` against `main` `940d32f` (not run: `victory-hle` is Windows-only). On the earlier comment that the `usize::MAX - PAGE + 1` test "hits the path that would panic in debug builds": as far as I can tell it does not reach the changed arithmetic. `end` was already `at.saturating_add(len)`, and `base + size` (`xmem.rs:412`, `:417`) can only overflow when a view in `physical().views` has `base + size > usize::MAX`. The test inserts no view, so `range(..=at).next_back()` finds nothing (or, if another test left a small view in the shared `PHYSICAL`, `base + size` is far from overflowing), and `starts` over `at + 1..end` is empty. So `aliases_handles_saturating_range_bounds` should pass on `main` too, 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 + 1` with a size of `2 * PAGE`, call `aliases` on that range, and assert the result. Could someone on Windows confirm what the current test does with the two `saturating_add` lines reverted? AI-assisted analysis.
Author
Owner

@⁠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 into physical().views at usize::MAX - PAGE + 1 with size 2 * PAGE, and call aliases(top + 1, PAGE, &mut out) so both base.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)

**@⁠pushkarreddyy** on GitHub · 2026-11-25 14:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#issuecomment-7165087379) 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 into `physical().views` at `usize::MAX - PAGE + 1` with size `2 * PAGE`, and call `aliases(top + 1, PAGE, &mut out)` so both `base.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)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:32 UTC · original

Automated triage for the maintainers.

Proposed close. This changes *base + size and base + size in crates/victory-hle/src/modules/xmem.rs aliases to saturating_add. The keys of physical().views are the addresses of title views mapped into the process (views.insert(base, (len, slice)) in the mapping path), and their base + size stays inside the user address space, far below usize::MAX, so the overflow cannot happen. The new test reaches the changed lines only by inserting a view at usize::MAX - PAGE + 1 by 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

**@⁠Marvisak** on GitHub · 2026-11-25 15:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#issuecomment-7166997548) <!-- victory-triage v1 head=c31504961eb48597b72c30f7ef7cd27141590ff2 verdict=proposed-close at=2026-11-25T15:36:00Z --> Automated triage for the maintainers. **Proposed close.** This changes `*base + size` and `base + size` in `crates/victory-hle/src/modules/xmem.rs` `aliases` to `saturating_add`. The keys of `physical().views` are the addresses of title views mapped into the process (`views.insert(base, (len, slice))` in the mapping path), and their `base + size` stays inside the user address space, far below `usize::MAX`, so the overflow cannot happen. The new test reaches the changed lines only by inserting a view at `usize::MAX - PAGE + 1` by 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](https://claude.ai/code)_
github-bot closed this pull request 2026-11-26 15:19:52 +00:00
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 13:18 UTC · original · approved these changes

Verified against origin/main (940d32f):

  • Using saturating_add for view end bounds in xmem::aliases cleanly prevents overflow on malformed/near-max ranges (#2413).
  • cargo test -p victory-hle xmem::: 11/11 passed (including aliases_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).

**@⁠DenRakEiw** on GitHub · 2026-11-25 13:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#pullrequestreview-6058334948) · **approved these changes** Verified against `origin/main` (`940d32f`): - Using `saturating_add` for view end bounds in `xmem::aliases` cleanly prevents overflow on malformed/near-max ranges (`#2413`). - `cargo test -p victory-hle xmem::`: 11/11 passed (including `aliases_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).
Author
Owner

@⁠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.

**@⁠catminou4** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#pullrequestreview-6058346769) · **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.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-26 15:19 UTC · original

Closing this PR after reviewing the triage verification on main:

  • physical().views only records user-space mapped addresses well below usize::MAX, so base + size in aliases cannot overflow during real xmem execution.

Thank you for the audit.

AI-assisted: yes (Gemini 4 Neon)

**@⁠pushkarreddyy** on GitHub · 2026-11-26 15:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2421#issuecomment-7196097724) Closing this PR after reviewing the triage verification on `main`: - `physical().views` only records user-space mapped addresses well below `usize::MAX`, so `base + size` in `aliases` cannot overflow during real `xmem` execution. Thank you for the audit. AI-assisted: yes (Gemini 4 Neon)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2421
No description provided.