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

Merged
AndyLatimer merged 2 commits from upstream-pr/88 into main 2026-11-24 08:47:09 +00:00
AndyLatimer commented 2026-11-24 00:22:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-24T00:22:01Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571704692 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/88). Originally posted by [AndyLatimer](https://github.com/AndyLatimer) on 2026-11-24T00:22:01Z. --- 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)
DaviTostes commented 2026-11-24 06:54:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:13:11Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118880624 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/88#issuecomment-7118880624). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:13:11Z. --- 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.
upstream-sync closed this pull request 2026-11-24 09:04:57 +00:00
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!88
No description provided.