Skip to content

GPU/inplace+watch: guard zero-length ranges and VEH fault overflow - #622

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-inplace-and-watch-zero-len-panic-and-overflow
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-inplace-and-watch-zero-len-panic-and-overflow

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

Problem

Zero-length ranges and fault-address edge cases in crates/victory-gpu/src/inplace.rs and crates/victory-gpu/src/watch.rs could panic inside BTreeMap/BTreeSet::range or strip guards from untouched blocks:

  1. inplace::views_gone(at, 0) panicked unconditionally whenever VIEWS was non-empty: with len == 0 and at < usize::MAX, end == at, so v.views.range(at.saturating_add(1)..end) evaluated (at + 1)..at and panicked while holding the global VIEWS mutex (and across extern "system" FFI callers of title_memory_remapped).
  2. watch::title_memory_remapped(at, 0) and watch::writing(at, 0) stripped guards on unaligned addresses: at / BLOCK .. at.div_ceil(BLOCK) evaluates to k..(k + 1) when at is not BLOCK-aligned, erroneously unguarding/clearing an untouched block (and watch::open panicked if start > end).
  3. watch::on_write computed at + 1 unchecked inside the extern "system" VEH, overflowing/wrapping if at == usize::MAX.

Fix

  • Early-return on len == 0 in inplace::views_gone, inplace::title_memory_freeing, watch::title_memory_remapped, and watch::writing (and use base.saturating_add(view.0) in views_gone).
  • Early-return on start >= end in watch::open, and use at.checked_add(1) in watch::on_write.
  • Add synthetic unit tests views_gone_ignores_zero_length_without_panicking and zero_length_remap_and_writing_do_not_panic_or_unguard.

Verification

  • cargo test -p victory-gpu --locked inplace:: -- --test-threads=1: 7 passed, 0 failed
  • cargo test -p victory-gpu --locked watch:: -- --test-threads=1: 8 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean (default-features build on c96b4f2 has only the pre-existing dead_code warning on placed_filler_twins, tracked in GPU: keep clippy green without the diagnostics feature #491)

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

- `inplace::views_gone(at, 0)` evaluated `v.views.range((at + 1)..at)` whenever
  any view was registered, panicking unconditionally inside `BTreeMap::range`
  while holding the global `VIEWS` mutex (and across FFI callers of
  `title_memory_remapped`).
- `watch::title_memory_remapped(at, 0)` and `watch::writing(at, 0)` with an
  unaligned `at` computed `k..(k + 1)`, stripping guard/absent tracking from an
  untouched block (and `watch::open` panicked if `start > end`).
- `watch::on_write` computed `at + 1` inside the `extern "system"` VEH,
  overflowing/wrapping if `at == usize::MAX`.

Guard `len == 0` in `inplace::views_gone`, `inplace::title_memory_freeing`,
`watch::title_memory_remapped`, and `watch::writing`, guard `start >= end` in
`watch::open`, use `checked_add(1)` in `watch::on_write`, and add synthetic
unit tests in both modules.
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
…ort of fxceless fxceless#622)

views_gone(at, 0) made an inverted BTreeMap range and panicked under the
VIEWS mutex; zero-length remaps and writes at an unaligned address opened
a block nothing touched; the write handler's at + 1 could overflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBCi8h4eymnRhdth77t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant