Skip to content

Fix #2413: use saturating_add for view end bounds in aliases - #3017

Closed
tharun-37 wants to merge 1 commit into
Marvisak:mainfrom
tharun-37:fix/xmem-saturating-add
Closed

tharun-37 wants to merge 1 commit into
Marvisak:mainfrom
tharun-37:fix/xmem-saturating-add

Conversation

@tharun-37

@tharun-37 tharun-37 commented Nov 26, 2026 •

Copy link
Copy Markdown

Fix #2413: use saturating_add for view end bounds in aliases

In xmem::aliases, end uses saturating_add but the view-range checks used unchecked addition (*base + size, base + size), which can overflow/panic. Use saturating_add consistently.

Additionally:

  • Return early when end <= at (empty or wrapping query) to avoid reversed BTreeMap range panic
  • Added unit tests for empty query, overflow saturation, and query past view end

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review on 541938dc (static source inspection):

  • P2 — Unrelated emit/lower.rs (med3 / nan_safe_min / nan_safe_max) changes bundled in this PR:
    • The diff modifies crates/victory-shader/src/emit/lower.rs:2266-2295 in addition to xmem.rs, which is unrelated to #2413 (aliases view end bounds) and appears to come from a separate branch/base. Please drop the lower.rs hunk and rebase onto current main.
  • P2 — aliases still panics on empty (len == 0) queries (crates/victory-hle/src/modules/xmem.rs:405-419):
    • When len == 0 (e.g., aliases(0x10000, 0, &mut out)), end == at, so physical.views.range(at.saturating_add(1)..end) passes a reversed range (0x10001..0x10000) to BTreeMap::range and panics. Returning early when end <= at (and adding a unit test for both empty and overflowing queries) completes the bounds fix.

@futurepro62

Copy link
Copy Markdown

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 541938d (on its base 940d32f).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@tharun-37
tharun-37 force-pushed the fix/xmem-saturating-add branch from f68ea14 to 73227f8 Compare November 26, 2026 04:35

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the fix itself (end<=at early-out, saturating_add on both bound comparisons, boundary tests all discriminate). Heads-up: #3037 contains this identical xmem/aliases change plus its write-watch fix — whichever merges second gets a conflict; may be worth rebasing one onto the other.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Thanks for the reply and for updating the description. The head is unchanged, and you agree the guards in xmem.rs::aliases fix no reachable case, so the proposed close stands. The PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label triage: proposed close.


Generated by Claude Code

@tharun-37

Copy link
Copy Markdown
Author

Removed the decompiled-code attribution from the description per the asset policy.

On the first point: you're right that �liases has no real caller on main except its own test, so these guards fix no live bug today. The saturating_add change is still correct defensive hygiene (the original code could panic on usize::MAX inputs), but I agree the early-return and tests are mostly defensive. If you'd prefer to close this and land just the core saturating_add one-liner as #90 already does in larger PRs (#1017, #39, #523, #1241), I'm fine with that — closing #3017.

@tharun-37

Copy link
Copy Markdown
Author

Closing to focus on new issues

@tharun-37 tharun-37 closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xmem: use saturating_add for view end bounds in aliases

5 participants