XMA: noise tests, and end a frame at its data instead of looping forever #183
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!183
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/183/head"
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?
@AnoHunted on GitHub · 2026-11-24 01:14 UTC · original
AnoHunted:xma-noise-tests→main· +238 −1 · 1 files · 1 commits · merged 2026-11-25 00:19 UTCWhat
Decoder::decodeends a frame's bits at the end of its data:end: bits.min(data.len().saturating_mul(8)). A frame fromread_framealways holds its bits(
data.len() == bits.div_ceil(8)), so its decoding does not change.xma.rs, like BCPack'snoise_never_panics: xorshift64, fixedseeds, bounded rounds, no new dependencies.
noise_packets_walk_and_decode: 60 buffers of 1 to 4 packets: pure noise, streams of noiseframes with consistent headers (the test lays them out), and such streams with damaged headers
and flipped bits. It walks the frames from the first packet as
audio.rsdoes and decodes each,mono and stereo. Each
nextmust lie after its frame, the walk must stay withinbits / 16frames, every decode must append one frame of samples (flush half a frame), and a clean stream
must give every frame it holds.
noise_frames_decode_to_a_frame_of_samples: noise frames of 0 to 4095 bytes, mono and stereo at24, 32, 44.1 and 48 kHz, with bit counts up to the end of the data.
noise_frames_with_bit_counts_past_the_data: short noise frames (0 to 300 bytes) with bit countspast the data, up to
usize::MAX.noise_offsets_read_a_frame_or_nothing:read_framefrom packet edges, the end of the buffer,usize::MAX / 2, the last packet-aligned bit belowusize::MAX,usize::MAXand random bits;packetat indices up tousize::MAX. A frame read must have a length of 16 to 32766 bits, thatmany bits of data, and a
nextafter its start and inside the buffer.Why
decodetook itsbitsargument as the end of the frame. Past the data the bit reader returnszeros. In a stereo tile header, zero bits give the subframe to no channel, so
min_channel_lenfalls back and the loop never moves on; its only way out is then
overread(), which a count past thedata never reaches. One byte of data with a count of about
usize::MAX / 2spun for good. A monotile header always moves on, so only stereo hung.
No caller passes such a count today:
audio.rshandsdecodetheFramethatread_framebuilt.The change makes
decodesafe on its own, as a public entry point that takes a size.Nothing else failed. The decoder and the frame walk also held up in a one-off run on main with 20
times the rounds and 400,000 mutated frames (281,000 of them decoded to non-silent samples, so the
scale factor, coefficient and channel transform paths ran). That run used a harness with a panic
catcher per case and a time limit, so a hang could not stall the run; it was for
finding failures only and is not part of this change.
Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1.
cargo test -p victory-formats --lib xma::tests::noise_ -- --test-threads=1hung innoise_frames_with_bit_counts_past_the_data(2 channels, round 1: 1 byte, 9223372036855139009 bits); the three other tests passed, also at 20
times the rounds.
cargo test -p victory-formats --lib xma::gives 9 passed, 2 ignored (they need filesoutside the repository). The four noise tests take 0.14 s together in a debug build
(
--report-time: 0.058, 0.017, 0.002 and 0.067 s).cargo test --workspace -- --test-threads=4, run side by side: main 264 passed, 0 failed,4 ignored; this branch 268 passed (the four new tests), 0 failed, 4 ignored.
cargo clippy -p victory-formats --tests: no warnings.cargo fmt --checkreports nothing in thechanged lines (the crate has older differences, which this does not touch).
cargo test -p victory-formats --lib xma::gives10 passed, 2 ignored.
Not tested
walks_saved_streams,matches_a_reference_decoderneed files outside the repository); a title.
Open PRs on this file: #96 (
next_frame), #112 (formatting ofxma.rs) and #172 (IMDCT tables)touch
xma.rs; each merges with this branch without a textual conflict (git merge-tree), and thetests here pass with #96 merged in (not run with #112 or #172). #88 changes only
audio.rs. Thepacketoffset fix of #50 is already on main.AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.
@DaviTostes on GitHub · 2026-11-24 01:23 UTC · original
Tested
d4d1822on Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-formats: 24 passed, 0 failed, 3 ignored (2 test binaries), including the 4 tests this PR adds.No game data used.
@yuruiwang233 on GitHub · 2026-11-24 14:41 UTC · original
Independent verification on Windows 11, x86_64-pc-windows-gnu (rustc 1.98.1, MinGW-w64 15.2; GNU toolchain, not the MSVC one CI uses).
cargo test -p victory-formats --lib --locked: 27 passed, 0 failed, 4 ignored.cargo test -p victory-formats --lib xma::: 9 passed, 0 failed, 2 ignored (the two reference-file tests), in 0.25 s.cargo clippy -p victory-formats --all-targets --locked -- -D warnings: clean.Regression check: I kept the new tests and restored only
end: bits.xma::tests::noise_frames_with_bit_counts_past_the_datawas still running after 90 s and had to be killed; with the clamp it finishes in 0.25 s in the same binary. So the spin is real and this line is what ends it.Scope of the behaviour change, from reading the code:
read_framebuildsdataasbits.div_ceil(8)bytes, sobits <= data.len() * 8holds for every frame the walker produces and the clamp is a no-op there. It only changes directdecode(data, bits, ...)calls whosebitsexceed the buffer, whereBits::peek32used to read zeros past the data. For those,overread()now trips at the data end instead of atbits, the frame returnsErr, and the caller keeps the stream timing as it already did.Not verified here: real streams (
VICTORY_XMA_STREAMSdata outside the repo) and the reference decoder comparison.@Marvisak on GitHub · 2026-11-25 00:21 UTC · original
Automated triage for the maintainers.
Merge candidate (mainly for the tests).
Decoder::decodeincrates/victory-formats/src/xma.rsnow clamps the bit reader's end to the data (bits.min(data.len() * 8)); before, a bit count past the data made a stereo tile header spin forever on zero bits. The only caller,decodeincrates/victory-hle/src/modules/audio.rs, passes aFramefromread_framewhose data always holds its bits, so this does not change behaviour in a run; it makes the public entry point safe on its own. Most of the value is the four deterministic noise tests (noisy and damaged streams, all sample rates, bit counts past the data,read_frame/packetat edge offsets), with no new dependencies.CI: no check runs on the head commit.
Generated by Claude Code