Audio, watch: no overflow on huge title sizes (XMA read advance, fread) #88
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/88"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_READcomputed(read block + blocks) % sizeinu32.blocksis the title's count, passed through unchecked, and the read block is a 5-bit field. A count nearu32::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_writeandtitle_memory_remapped):freadpassessize.saturating_mul(count)as the length, butwritingthen computedat + lenunchecked.fread(buf, 1, SIZE_MAX, f)overflowed.title_memory_remappedhad 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).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.xma_contexts_decode_into_their_output_ringsnow advances read block 3 byu32::MAXon a ring of four and expects block 2.cargo clippy --workspace --all-targets: 0 warnings.cargo xtask policy: pass (148 files).rustfmt --checkreports no differences in the changed lines. The other diffs in these files already exist onmain.🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:13:11Z.
Tested
ec0d155: pass, no regression.d3dcompiler_47for the shader compiler.: 36 passed, 1 failed.resource::tests::buffer_data_reaches_the_host_texture, i.e. #128, not this PR. The new watch test passes.No game data used.