GPU/list+draw: fix integer overflows and unchecked buffer bounds in resolve_queries, execute_indirect, and rectangles #480

Open
AscilCH wants to merge 1 commit from upstream-pr/480 into main
AscilCH commented 2026-11-25 01:22:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T01:22:57Z.


Problem

Three GPU command-recording bounds checks in crates/victory-gpu/src/list.rs and crates/victory-gpu/src/draw.rs used unchecked or narrow integer arithmetic:

  1. list::resolve_queries (list.rs:1362): if offset + u64::from(count) * bytes > size used unchecked u64 arithmetic. A large offset (e.g. u64::MAX - 4 with count = 1) panicked in debug builds and wrapped around in release builds to pass the guard, calling data.add(offset as usize) + defer_write out of bounds.
  2. list::execute_indirect (list.rs:1696-1697): buffer_bytes(arguments).map(|(p, _)| p as u64 + offset) and buffer_bytes(count).map(|(p, _)| p as u64 + count_offset) discarded buffer size completely and used unchecked +, allowing out-of-bounds or wrapping offsets to reach into an adjacent buffer's Shadow.
  3. draw::State::rectangles (draw.rs:2181-2189, 2212): u64::from(first + count) * stride > u64::from(v.size) added first + count in u32 before widening to u64 (wrapping to 0 on e.g. 0x8000_0000 + 0x8000_0000), computed v.address + u64::from(first) * stride unchecked, and truncated (rects * 6 * stride) as u32 into SizeInBytes.

Fix

  • Use checked_mul and checked_add in list::resolve_queries.
  • Add checked_buffer_offset(buffer, offset, len) in list.rs and validate both arguments (stride * max.max(1)) and count (4) against their buffer sizes in execute_indirect.
  • Extract rect_vertex_span in draw.rs widening u64::from(first) + u64::from(count), using checked arithmetic for address/byte spans, and validating u32::try_from(dst_bytes).
  • Add synthetic unit tests resolve_queries_and_execute_indirect_reject_overflowing_offsets and rect_vertex_span_rejects_overflow_and_out_of_bounds.

Verification

  • cargo test -p victory-gpu --locked list::tests -- --test-threads=1: 2 passed, 0 failed
  • cargo test -p victory-gpu --locked draw::tests -- --test-threads=1: 1 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594942175 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/480). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T01:22:57Z. --- ## Problem Three GPU command-recording bounds checks in `crates/victory-gpu/src/list.rs` and `crates/victory-gpu/src/draw.rs` used unchecked or narrow integer arithmetic: 1. **`list::resolve_queries` (`list.rs:1362`)**: `if offset + u64::from(count) * bytes > size` used unchecked `u64` arithmetic. A large `offset` (e.g. `u64::MAX - 4` with `count = 1`) panicked in debug builds and wrapped around in release builds to pass the guard, calling `data.add(offset as usize)` + `defer_write` out of bounds. 2. **`list::execute_indirect` (`list.rs:1696-1697`)**: `buffer_bytes(arguments).map(|(p, _)| p as u64 + offset)` and `buffer_bytes(count).map(|(p, _)| p as u64 + count_offset)` discarded buffer `size` completely and used unchecked `+`, allowing out-of-bounds or wrapping offsets to reach into an adjacent buffer's `Shadow`. 3. **`draw::State::rectangles` (`draw.rs:2181-2189, 2212`)**: `u64::from(first + count) * stride > u64::from(v.size)` added `first + count` in `u32` before widening to `u64` (wrapping to `0` on e.g. `0x8000_0000 + 0x8000_0000`), computed `v.address + u64::from(first) * stride` unchecked, and truncated `(rects * 6 * stride) as u32` into `SizeInBytes`. ## Fix - Use `checked_mul` and `checked_add` in `list::resolve_queries`. - Add `checked_buffer_offset(buffer, offset, len)` in `list.rs` and validate both `arguments` (`stride * max.max(1)`) and `count` (`4`) against their buffer sizes in `execute_indirect`. - Extract `rect_vertex_span` in `draw.rs` widening `u64::from(first) + u64::from(count)`, using checked arithmetic for address/byte spans, and validating `u32::try_from(dst_bytes)`. - Add synthetic unit tests `resolve_queries_and_execute_indirect_reject_overflowing_offsets` and `rect_vertex_span_rejects_overflow_and_out_of_bounds`. ## Verification - `cargo test -p victory-gpu --locked list::tests -- --test-threads=1`: 2 passed, 0 failed - `cargo test -p victory-gpu --locked draw::tests -- --test-threads=1`: 1 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/480:upstream-pr/480'
git switch 'upstream-pr/480'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/480'
git switch 'upstream-pr/480'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/480'
git switch 'upstream-pr/480'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/480'
git switch 'main'
git merge --squash 'upstream-pr/480'
git switch 'main'
git merge --ff-only 'upstream-pr/480'
git switch 'main'
git merge 'upstream-pr/480'
git push origin 'main'
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
fxceless/victory-fork!480
No description provided.