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

Closed
tharun-37 wants to merge 1 commit from upstream-pr/3017 into main
tharun-37 commented 2026-11-26 03:29:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T03:29:41Z.


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
<!-- greyfinch-sync:Marvisak/VIctory:issue:6618873924 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T03:29:41Z. --- 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 commented 2026-11-26 04:06:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:43:39Z.

Review: CHANGES_REQUESTED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6068259338 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017#pullrequestreview-6068259338). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:43:39Z. **Review:** CHANGES_REQUESTED --- 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 commented 2026-11-26 04:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T03:47:44Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7182029964 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7182029964). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T03:47:44Z. --- 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.
kotekompotek commented 2026-11-26 05:03:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:37:42Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068615057 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017#pullrequestreview-6068615057). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:37:42Z. **Review:** APPROVED --- 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 2026-11-26 07:01:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:15:34Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184250370 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7184250370). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:15:34Z. --- <!-- 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)_
tharun-37 commented 2026-11-26 07:01:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T06:18:01Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184292475 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7184292475). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T06:18:01Z. --- 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.
upstream-sync closed this pull request 2026-11-26 10:04:39 +00:00
tharun-37 commented 2026-11-26 10:05:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T09:57:57Z.


Closing to focus on new issues

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188720445 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3017#issuecomment-7188720445). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T09:57:57Z. --- Closing to focus on new issues

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3015
No description provided.