gpu: use checked addition and forward-progress guards in committed memory queries #38

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

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


Problem

In crates/victory-gpu/src/texture.rs (committed_by_query) and crates/victory-gpu/src/port.rs (committed):

  1. p + len / t + len uses unchecked addition — overflowing ranges panic in debug builds and wrap end < at in release builds, skipping the loop and falsely returning rue.
  2. Neither loop verifies forward progress (
    ext <= p /
    ext <= here), unlike exture::unmapped immediately below committed_by_query, so a zero-size or non-advancing VirtualQuery region would spin indefinitely (and exture::committed_by_query also used unchecked BaseAddress as usize + RegionSize).

Fix

Use checked_add(len) (returning alse on overflow), saturating_add(info.RegionSize), and a
ext <= p /
ext <= here forward-progress guard in both functions, with unit tests (committed_by_query_rejects_overflowing_range and committed_rejects_overflowing_range).

Verification

  • cargo test -p victory-gpu --lib -- committed_by_query_rejects_overflowing_range port::tests (4 passed, 0 failed)
  • cargo clippy -p victory-gpu --tests (0 warnings)
<!-- greyfinch-sync:edsuuu/VI-BR-PORT:issue:5550805058 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/38). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T12:41:39Z. --- ## Problem In crates/victory-gpu/src/texture.rs (committed_by_query) and crates/victory-gpu/src/port.rs (committed): 1. p + len / t + len uses unchecked addition — overflowing ranges panic in debug builds and wrap end < at in release builds, skipping the loop and falsely returning rue. 2. Neither loop verifies forward progress ( ext <= p / ext <= here), unlike exture::unmapped immediately below committed_by_query, so a zero-size or non-advancing VirtualQuery region would spin indefinitely (and exture::committed_by_query also used unchecked BaseAddress as usize + RegionSize). ## Fix Use checked_add(len) (returning alse on overflow), saturating_add(info.RegionSize), and a ext <= p / ext <= here forward-progress guard in both functions, with unit tests (committed_by_query_rejects_overflowing_range and committed_rejects_overflowing_range). ## Verification - cargo test -p victory-gpu --lib -- committed_by_query_rejects_overflowing_range port::tests (4 passed, 0 failed) - cargo clippy -p victory-gpu --tests (0 warnings)
edsuuu commented 2026-11-29 13:20:53 +00:00 (Migrated from github.com)

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

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:6103050824 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/38#pullrequestreview-6103050824). Originally posted by [edsuuu](https://github.com/edsuuu) on 2026-11-29T13:20:53Z. **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!38
No description provided.