gpu: handle zero-length ranges safely in inplace, texback, port, and descriptor #36

Merged
ahmetbagci8 merged 1 commit from upstream-pr/36 into dev 2026-11-29 13:19:38 +00:00
ahmetbagci8 commented 2026-11-29 12:38:11 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T12:38:11Z.


Problem

Four half-open range helpers in ictory-gpu did not guard against len == 0:

  1. inplace::views_gone(at, 0): .views.range(at.saturating_add(1)..end) panics in BTreeMap::range (
    ange start is greater than range end) whenever t < usize::MAX, and irst removes a live view containing t.
  2. exback::remapped(at, 0): t < ticket.end && ticket.at < end evaluates to rue when icket.at < at < ticket.end, falsely invalidating a live readback ticket.
  3. port::forget(at, 0) and port::touches(at, 0): an empty range inside a live region evicts the region / returns rue.
  4. descriptor::in_shader_heap(at, 0): returns rue when start < at < end, and t as u64 + len as u64 uses unchecked addition.

Fix

Return early on len == 0 in all four functions (and use saturating_add in in_shader_heap), with unit tests covering each case.

Verification

  • cargo test -p victory-gpu --lib -- inplace::tests texback::tests port::tests in_shader_heap_rejects_empty_ranges_and_saturates_length (14 passed, 0 failed)
  • cargo clippy -p victory-gpu --tests (0 warnings)
<!-- greyfinch-sync:edsuuu/VI-BR-PORT:issue:5550778928 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/36). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T12:38:11Z. --- ## Problem Four half-open range helpers in ictory-gpu did not guard against len == 0: 1. inplace::views_gone(at, 0): .views.range(at.saturating_add(1)..end) panics in BTreeMap::range ( ange start is greater than range end) whenever t < usize::MAX, and irst removes a live view containing t. 2. exback::remapped(at, 0): t < ticket.end && ticket.at < end evaluates to rue when icket.at < at < ticket.end, falsely invalidating a live readback ticket. 3. port::forget(at, 0) and port::touches(at, 0): an empty range inside a live region evicts the region / returns rue. 4. descriptor::in_shader_heap(at, 0): returns rue when start < at < end, and t as u64 + len as u64 uses unchecked addition. ## Fix Return early on len == 0 in all four functions (and use saturating_add in in_shader_heap), with unit tests covering each case. ## Verification - cargo test -p victory-gpu --lib -- inplace::tests texback::tests port::tests in_shader_heap_rejects_empty_ranges_and_saturates_length (14 passed, 0 failed) - cargo clippy -p victory-gpu --tests (0 warnings)
edsuuu commented 2026-11-29 13:19:36 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by edsuuu on 2026-11-29T13:19:36Z.

Review: APPROVED


Thanks, clean and well tested. It passed our full local CI together with the other fixes of this batch. Merged into dev, where everything is tested in the game first; it reaches main with the next release.

<!-- greyfinch-sync:edsuuu/VI-BR-PORT:review:6103046529 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/36#pullrequestreview-6103046529). Originally posted by [edsuuu](https://github.com/edsuuu) on 2026-11-29T13:19:36Z. **Review:** APPROVED --- Thanks, clean and well tested. It passed our full local CI together with the other fixes of this batch. Merged into `dev`, where everything is tested in the game first; it reaches `main` with the next release.
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
edsuuu/VI-BR-PORT!36
No description provided.