GPU: handle empty and inverted ranges in watch::writes, writing, and title_memory_remapped #1332

Closed
mgunes1311-lab wants to merge 1 commit from upstream-pr/1332 into main
mgunes1311-lab commented 2026-11-24 17:30:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-24T17:30:20Z.


Fixes guard corruption and integer underflow on empty, unaligned-empty, and inverted byte/address ranges in crates/victory-gpu/src/watch.rs:

Changes

  • Early-return on len == 0 in writing and title_memory_remapped: an unaligned empty range previously rounded to a nonempty block range. writing unnecessarily opened and dirtied that block. title_memory_remapped could remove its protection bookkeeping while the OS mapping remained read-only, so the next write fault was no longer recognized by on_write.
  • Early-return false in open when start >= end so BTreeSet::range cannot panic on inverted bounds.
  • Early-return Some((j.asked, Vec::new())) in writes when start >= end (avoiding last - first underflow or GetWriteWatch(..., size = 0) failure), and use last.saturating_mul(PAGE) when delegating to guard.
  • Added synthetic test empty_and_inverted_ranges_do_not_corrupt_guards_or_underflow.

Verification

  • cargo test -p victory-gpu --target x86_64-pc-windows-msvc --locked watch:: (4 passed; 0 failed)
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --target x86_64-pc-windows-msvc --locked
  • cargo run -p xtask --target x86_64-pc-windows-msvc --locked -- policy --staged (asset policy: 1 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587648643 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1332). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-24T17:30:20Z. --- Fixes guard corruption and integer underflow on empty, unaligned-empty, and inverted byte/address ranges in `crates/victory-gpu/src/watch.rs`: ### Changes - Early-return on `len == 0` in `writing` and `title_memory_remapped`: an unaligned empty range previously rounded to a nonempty block range. `writing` unnecessarily opened and dirtied that block. `title_memory_remapped` could remove its protection bookkeeping while the OS mapping remained read-only, so the next write fault was no longer recognized by `on_write`. - Early-return `false` in `open` when `start >= end` so `BTreeSet::range` cannot panic on inverted bounds. - Early-return `Some((j.asked, Vec::new()))` in `writes` when `start >= end` (avoiding `last - first` underflow or `GetWriteWatch(..., size = 0)` failure), and use `last.saturating_mul(PAGE)` when delegating to `guard`. - Added synthetic test `empty_and_inverted_ranges_do_not_corrupt_guards_or_underflow`. ### Verification - `cargo test -p victory-gpu --target x86_64-pc-windows-msvc --locked watch::` (`4 passed; 0 failed`) - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --target x86_64-pc-windows-msvc --locked` - `cargo run -p xtask --target x86_64-pc-windows-msvc --locked -- policy --staged` (`asset policy: 1 files ok`)
catminou4 commented 2026-11-24 21:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:07:45Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS, so this is source review plus the PR's own Windows tests.

Empty and inverted ranges are handled before any page math: writes returns early for start >= end, guard uses last.saturating_mul(PAGE) instead of plain multiplication, and open/writing/title_memory_remapped all no-op on empty ranges. This removes the underflow/OOB that an inverted range (end < start) would have caused in last - first. The new test maps a real pagefile section, guards it, verifies empty/inverted ranges don't disturb guards, and confirms the VEH write-watch still fires for the guarded block. Windows-only; looks correct.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046527430 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1332#pullrequestreview-6046527430). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:07:45Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS, so this is source review plus the PR's own Windows tests. Empty and inverted ranges are handled before any page math: `writes` returns early for `start >= end`, `guard` uses `last.saturating_mul(PAGE)` instead of plain multiplication, and `open`/`writing`/`title_memory_remapped` all no-op on empty ranges. This removes the underflow/OOB that an inverted range (`end < start`) would have caused in `last - first`. The new test maps a real pagefile section, guards it, verifies empty/inverted ranges don't disturb guards, and confirms the VEH write-watch still fires for the guarded block. Windows-only; looks correct.
upstream-sync closed this pull request 2026-11-25 01:06:15 +00:00
Marvisak commented 2026-11-25 01:08:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:37:39Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Guards the old watch::writes and open against empty and inverted ranges; both are gone, and in main an empty range at worst marks one page changed.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148709854 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1332#issuecomment-7148709854). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:37:39Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Guards the old watch::writes and open against empty and inverted ranges; both are gone, and in main an empty range at worst marks one page changed. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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
Marvisak/VIctory!1332
No description provided.