GPU: clamp Staging::detile slices and harden page readability checks #165

Open
HailLucifer666 wants to merge 2 commits from upstream-pr/165 into main
HailLucifer666 commented 2026-11-24 22:06:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-24T22:06:10Z.


Problem

  • Staging::detile() built a mutable slice of pitch * rows * depth even when GetCopyableFootprints omits trailing row-pitch padding on the final row, exceeding self.bytes (UB).
  • readable() used at.saturating_add(len - 1), which saturates to usize::MAX on address overflow and loops across the 64-bit address space instead of rejecting the range.
  • committed_by_query() used unchecked p + len, and both VirtualQuery paths (committed_by_query and mapped_bytes) counted PAGE_NOACCESS and PAGE_GUARD pages as readable committed memory.

Fix

  • Clamp Staging::detile() slices via subresource_len(..., self.bytes).
  • Use checked_add in readable(), committed_by_query(), and mapped_bytes().
  • Share is_readable_commit() across both VirtualQuery paths to reject PAGE_NOACCESS and PAGE_GUARD.

Verification

  • Added unit tests for subresource_len and real VirtualAlloc PAGE_NOACCESS / PAGE_GUARD / PAGE_READWRITE + usize::MAX overflow cases.
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test -p victory-gpu texture:: --locked (4/4 passed)
  • cargo test -p xtask --locked (4/4 passed)
<!-- greyfinch-sync:fxceless/victory-fork:issue:6592348931 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/165). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-24T22:06:10Z. --- ### Problem - `Staging::detile()` built a mutable slice of `pitch * rows * depth` even when `GetCopyableFootprints` omits trailing row-pitch padding on the final row, exceeding `self.bytes` (UB). - `readable()` used `at.saturating_add(len - 1)`, which saturates to `usize::MAX` on address overflow and loops across the 64-bit address space instead of rejecting the range. - `committed_by_query()` used unchecked `p + len`, and both `VirtualQuery` paths (`committed_by_query` and `mapped_bytes`) counted `PAGE_NOACCESS` and `PAGE_GUARD` pages as readable committed memory. ### Fix - Clamp `Staging::detile()` slices via `subresource_len(..., self.bytes)`. - Use `checked_add` in `readable()`, `committed_by_query()`, and `mapped_bytes()`. - Share `is_readable_commit()` across both `VirtualQuery` paths to reject `PAGE_NOACCESS` and `PAGE_GUARD`. ### Verification - Added unit tests for `subresource_len` and real `VirtualAlloc` `PAGE_NOACCESS` / `PAGE_GUARD` / `PAGE_READWRITE` + `usize::MAX` overflow cases. - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `cargo test -p victory-gpu texture:: --locked` (4/4 passed) - `cargo test -p xtask --locked` (4/4 passed)
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/165:upstream-pr/165'
git switch 'upstream-pr/165'

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