Return false on zero-length ranges and avoid overflow in in_shader_heap #438

Closed
github-bot wants to merge 660 commits from github-bot/gh-438 into main AGit
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-29 11:25 UTC · original
ahmetbagci8:fix/gpu-in-shader-heap-empty-range → main · +60048 −5429 · 206 files · 660 commits · closed without merging

Problem

In crates/victory-gpu/src/descriptor.rs, in_shader_heap(at, len) computes:

ust let (from, to) = (at as u64, at as u64 + len as u64); SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner()).iter().any(|&(start, end, _)| from < end && start < to)

  1. When len == 0 and start < at < end, rom == to == at, so rom < end && start < to evaluates to rue even though the half-open interval [at, at) is empty. (By contrast, ny_in_shader_heap immediately below already rejects o <= from.)
  2. t as u64 + len as u64 uses unchecked addition, which panics in debug builds or wraps in release builds if t + len > u64::MAX.

Fix

Return alse early when len == 0 and compute o with saturating_add. Added unit test in_shader_heap_rejects_empty_ranges_and_saturates_length.

Verification

  • cargo test -p victory-gpu --lib descriptor (76 passed, 0 failed)
  • cargo clippy -p victory-gpu --tests (0 warnings)
**@⁠ahmetbagci8** on GitHub · 2026-11-29 11:25 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/438) `ahmetbagci8:fix/gpu-in-shader-heap-empty-range` → `main` · +60048 −5429 · 206 files · 660 commits · closed without merging ## Problem In crates/victory-gpu/src/descriptor.rs, in_shader_heap(at, len) computes: ` ust let (from, to) = (at as u64, at as u64 + len as u64); SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner()).iter().any(|&(start, end, _)| from < end && start < to) ` 1. When len == 0 and start < at < end, rom == to == at, so rom < end && start < to evaluates to rue even though the half-open interval [at, at) is empty. (By contrast, ny_in_shader_heap immediately below already rejects o <= from.) 2. t as u64 + len as u64 uses unchecked addition, which panics in debug builds or wraps in release builds if t + len > u64::MAX. ## Fix Return alse early when len == 0 and compute o with saturating_add. Added unit test in_shader_heap_rejects_empty_ranges_and_saturates_length. ## Verification - cargo test -p victory-gpu --lib descriptor (76 passed, 0 failed) - cargo clippy -p victory-gpu --tests (0 warnings)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 11:27:23 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 11:35 UTC · original

Thanks for catching the empty-range case. Please include a boundary test near u64::MAX as well as a normal overlapping and non-overlapping range, so the saturation behavior is explicit. The reported descriptor suite is useful.

**@⁠TaynanGT** on GitHub · 2026-11-29 11:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/438#issuecomment-7255213978) Thanks for catching the empty-range case. Please include a boundary test near u64::MAX as well as a normal overlapping and non-overlapping range, so the saturation behavior is explicit. The reported descriptor suite is useful.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-29 12:58 UTC · original · reviewed

Ran this on Windows. cargo test -p victory-gpu --lib gives 528 passed (the descriptor group is 76), and cargo clippy -p victory-gpu --all-targets -D warnings is clean. With the old line put back, the new test fails on !in_shader_heap(address + 32, 0).

The two callers in host.rs (around 9275 and 9314) pass a copy's destination and length. A zero-length copy writes nothing, so answering false for it changes nothing there, and it now matches any_in_shader_heap.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-11-29 12:58 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/438#pullrequestreview-6102971048) · **reviewed** Ran this on Windows. `cargo test -p victory-gpu --lib` gives 528 passed (the descriptor group is 76), and `cargo clippy -p victory-gpu --all-targets -D warnings` is clean. With the old line put back, the new test fails on `!in_shader_heap(address + 32, 0)`. The two callers in `host.rs` (around 9275 and 9314) pass a copy's destination and length. A zero-length copy writes nothing, so answering false for it changes nothing there, and it now matches `any_in_shader_heap`. AI-assisted: yes
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 19:03 UTC · original

Thanks for the native regression run. I checked the diff: the new test covers an overlapping range, zero-length ranges, a saturating length, and an address at usize::MAX. The zero-length behavior is consistent with a copy that writes nothing. This is the narrow fix I wanted.

**@⁠TaynanGT** on GitHub · 2026-11-29 19:03 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/438#issuecomment-7260978542) Thanks for the native regression run. I checked the diff: the new test covers an overlapping range, zero-length ranges, a saturating length, and an address at usize::MAX. The zero-length behavior is consistent with a copy that writes nothing. This is the narrow fix I wanted.
github-bot closed this pull request 2026-11-30 17:08:40 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:07 UTC · original

main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:07 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/438#issuecomment-7285743763) `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.