Use checked addition and forward-progress guards in committed memory queries #455

Closed
ahmetbagci8 wants to merge 660 commits from upstream-pr/455 into main
ahmetbagci8 commented 2026-11-29 18:19:30 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by ahmetbagci8 on 2026-11-29T18:19:30Z.


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), and committed_by_query also uses 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:TaynanGT/Vice-Tay:issue:5553677369 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/455). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T18:19:30Z. --- ## 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), and committed_by_query also uses 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)
TaynanGT commented 2026-11-29 19:09:18 +00:00 (Migrated from github.com)

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


Thanks for guarding both the range end and the VirtualQuery loop's forward progress. Rejecting overflow before querying is the right behavior. Please retain normal committed/uncommitted range coverage as well as the new overflow cases; I haven't run the consolidated tests yet.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7261052122 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/455#issuecomment-7261052122). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T19:09:18Z. --- Thanks for guarding both the range end and the VirtualQuery loop's forward progress. Rejecting overflow before querying is the right behavior. Please retain normal committed/uncommitted range coverage as well as the new overflow cases; I haven't run the consolidated tests yet.
TaynanGT commented 2026-11-30 17:05:43 +00:00 (Migrated from github.com)

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


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:7285709819 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/455#issuecomment-7285709819). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:05:43Z. --- `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!455
No description provided.