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

Closed
ahmetbagci8 wants to merge 660 commits from upstream-pr/438 into main
ahmetbagci8 commented 2026-11-29 11:25:43 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by ahmetbagci8 on 2026-11-29T11:25:43Z.


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)
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5550239076 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/438). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T11:25:43Z. --- ## 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)
TaynanGT commented 2026-11-29 11:35:20 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:35:20Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7255213978 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/438#issuecomment-7255213978). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:35:20Z. --- 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.
Kal0s-design commented 2026-11-29 12:58:00 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Kal0s-design on 2026-11-29T12:58:00Z.

Review: COMMENTED


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

<!-- greyfinch-sync:TaynanGT/Vice-Tay:review:6102971048 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/438#pullrequestreview-6102971048). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-29T12:58:00Z. **Review:** COMMENTED --- 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
TaynanGT commented 2026-11-29 19:03:57 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T19:03:57Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7260978542 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/438#issuecomment-7260978542). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T19:03:57Z. --- 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 commented 2026-11-30 17:07:01 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:07:01Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285743763 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/438#issuecomment-7285743763). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:07:01Z. --- `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

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
TaynanGT/Vice-Tay!438
No description provided.