Audio, watch: no overflow on huge title sizes (XMA read advance, fread) #88

Manually merged
github merged 2 commits from gh-pr/88/head into gh-pr/88/base 2026-11-26 03:49:51 +00:00
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 00:22 UTC · original
AndyLatimer:fix/title-size-overflows → main · +22 −3 · 2 files · 2 commits · merged 2026-11-24 08:47 UTC

Two places added a size the title passes to another value in unchecked integer arithmetic. In debug builds that panics on overflow; in release it wraps.

XMA read advance (crates/victory-hle/src/modules/audio.rs, advance_read): ADVANCE_XMA_READ computed (read block + blocks) % size in u32. blocks is the title's count, passed through unchecked, and the read block is a 5-bit field. A count near u32::MAX (for example a wrapped difference of block numbers) overflowed. The count is now reduced modulo the ring size first: (read + blocks % size) % size. For every count that did not overflow, the result is the same.

Announced writes (crates/victory-gpu/src/watch.rs, writing / kernel_will_write and title_memory_remapped): fread passes size.saturating_mul(count) as the length, but writing then computed at + len unchecked. fread(buf, 1, SIZE_MAX, f) overflowed. title_memory_remapped had the same sum. Both ends now saturate at the top of the address space, so the range covers up to the end (the guarded blocks in it are opened, as for any write).

Testing

  • cargo test --workspace: 225 passed, 3 ignored (need external files).
    • New test: watch::ranges_past_the_address_space_end_do_not_overflow. It uses a range at the top of the address space, where no other test guards memory.
    • Extended test: xma_contexts_decode_into_their_output_rings now advances read block 3 by u32::MAX on a ring of four and expects block 2.
    • Both panic on the old code (checked by putting the old lines back).
  • cargo clippy --workspace --all-targets: 0 warnings.
  • cargo xtask policy: pass (148 files).
  • rustfmt --check reports no differences in the changed lines. The other diffs in these files already exist on main.
  • Tested with synthetic unit tests only (not run against a title).

🤖 Generated with Claude Code

**@⁠AndyLatimer** on GitHub · 2026-11-24 00:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/88) `AndyLatimer:fix/title-size-overflows` → `main` · +22 −3 · 2 files · 2 commits · merged 2026-11-24 08:47 UTC Two places added a size the title passes to another value in unchecked integer arithmetic. In debug builds that panics on overflow; in release it wraps. **XMA read advance** (`crates/victory-hle/src/modules/audio.rs`, `advance_read`): `ADVANCE_XMA_READ` computed `(read block + blocks) % size` in `u32`. `blocks` is the title's count, passed through unchecked, and the read block is a 5-bit field. A count near `u32::MAX` (for example a wrapped difference of block numbers) overflowed. The count is now reduced modulo the ring size first: `(read + blocks % size) % size`. For every count that did not overflow, the result is the same. **Announced writes** (`crates/victory-gpu/src/watch.rs`, `writing` / `kernel_will_write` and `title_memory_remapped`): `fread` passes `size.saturating_mul(count)` as the length, but `writing` then computed `at + len` unchecked. `fread(buf, 1, SIZE_MAX, f)` overflowed. `title_memory_remapped` had the same sum. Both ends now saturate at the top of the address space, so the range covers up to the end (the guarded blocks in it are opened, as for any write). ## Testing - `cargo test --workspace`: 225 passed, 3 ignored (need external files). - New test: `watch::ranges_past_the_address_space_end_do_not_overflow`. It uses a range at the top of the address space, where no other test guards memory. - Extended test: `xma_contexts_decode_into_their_output_rings` now advances read block 3 by `u32::MAX` on a ring of four and expects block 2. - Both panic on the old code (checked by putting the old lines back). - `cargo clippy --workspace --all-targets`: 0 warnings. - `cargo xtask policy`: pass (148 files). - `rustfmt --check` reports no differences in the changed lines. The other diffs in these files already exist on `main`. - Tested with synthetic unit tests only (not run against a title). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ADVANCE_XMA_READ added the title's block count to the 5-bit read block
in u32 before taking it modulo the ring size, so a count near u32::MAX
overflowed (a panic in debug builds). The count is reduced modulo the
ring first; the result is the same for every count that did not
overflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kernel_will_write (fread's size times count, saturated) and
title_memory_remapped added the length to the address unchecked, so a
huge fread count overflowed (a panic in debug builds). The end now
saturates at the top of the address space.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:49 +00:00
github manually merged commit ec0d155925 into gh-pr/88/base 2026-11-26 03:49:51 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:13 UTC · original

Tested ec0d155: pass, no regression.

  • Tested the Windows build under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), with a native Microsoft d3dcompiler_47 for the shader compiler.: 36 passed, 1 failed.
  • The only failure is resource::tests::buffer_data_reaches_the_host_texture, i.e. #128, not this PR. The new watch test passes.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/88#issuecomment-7118880624) Tested `ec0d155`: **pass, no regression**. - Tested the Windows build under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), with a native Microsoft `d3dcompiler_47` for the shader compiler.: **36 passed, 1 failed**. - The only failure is `resource::tests::buffer_data_reaches_the_host_texture`, i.e. #128, not this PR. The new watch test passes. No game data used.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!88
No description provided.