GPU: fix integer-overflow bounds checks in resolve_queries, execute_i… #537

Open
pug205gti6 wants to merge 1 commit from upstream-pr/537 into main
pug205gti6 commented 2026-11-25 02:01:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by pug205gti6 on 2026-11-25T02:01:37Z.


…ndirect, and State::rectangles

  1. list::resolve_queries: replace unchecked offset + u64::from(count) * bytes > size with checked multiplication and addition so wrapping offsets cannot panic in debug builds or bypass the buffer bounds check in release builds and schedule an out-of-bounds defer_write.
  2. list::execute_indirect: validate arguments ([offset, offset + stride * max.max(1))) and count ([count_offset, count_offset + 4)) against each buffer's recorded byte size using checked arithmetic (checked_buffer_offset), preventing out-of-bounds or wrapping offsets from aliasing adjacent Shadow buffers.
  3. draw::State::rectangles: widen u64::from(first) + u64::from(count) before multiplying by stride (avoiding u32 wrap on first + count), use checked addition for v.address + first * stride, and check u32::try_from(rects * 6 * stride) so D3D12_VERTEX_BUFFER_VIEW::SizeInBytes cannot silently truncate.

Add synthetic unit tests in list::tests and draw::tests.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595424792 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/537). Originally posted by [pug205gti6](https://github.com/pug205gti6) on 2026-11-25T02:01:37Z. --- …ndirect, and State::rectangles 1. `list::resolve_queries`: replace unchecked `offset + u64::from(count) * bytes > size` with checked multiplication and addition so wrapping offsets cannot panic in debug builds or bypass the buffer bounds check in release builds and schedule an out-of-bounds `defer_write`. 2. `list::execute_indirect`: validate `arguments` (`[offset, offset + stride * max.max(1))`) and `count` (`[count_offset, count_offset + 4)`) against each buffer's recorded byte size using checked arithmetic (`checked_buffer_offset`), preventing out-of-bounds or wrapping offsets from aliasing adjacent `Shadow` buffers. 3. `draw::State::rectangles`: widen `u64::from(first) + u64::from(count)` before multiplying by `stride` (avoiding `u32` wrap on `first + count`), use checked addition for `v.address + first * stride`, and check `u32::try_from(rects * 6 * stride)` so `D3D12_VERTEX_BUFFER_VIEW::SizeInBytes` cannot silently truncate. Add synthetic unit tests in `list::tests` and `draw::tests`.
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/537:upstream-pr/537'
git switch 'upstream-pr/537'

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/537'
git switch 'upstream-pr/537'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/537'
git switch 'upstream-pr/537'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/537'
git switch 'main'
git merge --squash 'upstream-pr/537'
git switch 'main'
git merge --ff-only 'upstream-pr/537'
git switch 'main'
git merge 'upstream-pr/537'
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!537
No description provided.