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

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

@⁠tharun-37 on GitHub · 2026-11-26 03:29 UTC · original
tharun-37:fix/xmem-saturating-add → main · +37 −2 · 1 files · 1 commits · closed without merging

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
**@⁠tharun-37** on GitHub · 2026-11-26 03:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017) `tharun-37:fix/xmem-saturating-add` → `main` · +37 −2 · 1 files · 1 commits · closed without merging 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:20:13 +00:00
github-bot force-pushed github-bot/gh-3017 from 541938dc11 to 73227f823b 2026-11-26 06:32:00 +00:00 Compare
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 03:47 UTC · original

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

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 696 passed, 0 failed, 10 ignored.
  • No new #[test] functions in the diff.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

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.
**@⁠futurepro62** on GitHub · 2026-11-26 03:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7182029964) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `541938d` (on its base `940d32f`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **696 passed, 0 failed, 10 ignored**. - No new `#[test]` functions in the diff. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:15 UTC · original · edited 2026-11-26 07:19 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-26 06:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7184250370) · edited 2026-11-26 07:19 UTC <!-- victory-triage v1 head=73227f823b80edde017c4c1652880b48f1a4f7f1 verdict=proposed-close at=2026-11-26T06:15:26Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠tharun-37 on GitHub · 2026-11-26 06:18 UTC · original

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** on GitHub · 2026-11-26 06:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7184292475) 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.
github-bot closed this pull request 2026-11-26 11:10:11 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 03:43 UTC · original · requested changes

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 03:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017#pullrequestreview-6068259338) · **requested changes** 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.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 04:37 UTC · original · approved these changes

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.

**@⁠kotekompotek** on GitHub · 2026-11-26 04:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017#pullrequestreview-6068615057) · **approved these changes** 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.
Author
Owner

@⁠tharun-37 on GitHub · 2026-11-26 09:57 UTC · original

Closing to focus on new issues

**@⁠tharun-37** on GitHub · 2026-11-26 09:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7188720445) Closing to focus on new issues

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!3017
No description provided.