Repository navigation
Port upstream #183: XMA ends a frame at its data instead of looping forever - #24
Merged
DesertGamer merged 1 commit intoNov 25, 2026
Merged
Conversation
5 of 7 tasks
2 of 23 tasks
Decoder::decode took the caller's bit count as the end of the frame. Past the data the bit reader returns zeros, and a stereo tile header reading only zeros gives the subframe to no channel, so it never moves on; with a count beyond the data it never overreads either, and looped for good. Clamp the end to the bits the data holds. A frame from read_frame always holds its bits, so its decoding does not change. Add deterministic noise tests (xorshift64, fixed seeds, as BCPack's): buffers of noise packets, streams of noise frames with clean and damaged headers, frames in mono and stereo at each sample rate, bit counts past the data, and read_frame and packet at any offset. Every walk is bounded and every decode must give one frame of samples. The bit-count test hangs without the fix; the others pass on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit d4d1822)
lcg007xd-c
force-pushed
the
port/upstream-183-xma-end
branch
from
November 25, 2026 21:45
8d26e62 to
2f0d75b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
This ports Marvisak/VIctory#183 by AnoHunted. It is cherry-picked with
-x, so the commit keeps their authorship.VIPort's history contains the upstream merge of #183 (338808e is an ancestor of
main), but the fix itself is not in the tree. Incrates/viport-formats/src/xma.rs,Decoder::decodestill setsend: bits, where upstream hasend: bits.min(data.len().saturating_mul(8)). The tests from #183 are missing too. The change was lost in a later merge.Without the clamp, a frame whose length field claims more bits than its buffer holds reads zeros past the end. On zero bits the subframe loop never moves forward, so the decoder spins forever. That hangs the audio thread on damaged or truncated XMA input.
The change: the one-line clamp, and #183's four noise tests (
noise_frames_*,noise_offsets_*,noise_packets_*). The only conflict was in the test module. I kept VIPort's existingstream_frame_count/counts_only_packets_in_the_selected_streamtests and put #183's tests after them. The doc comment ofwalks_saved_streamskeepsVIPORT_XMA_STREAMS.Checked
docs/asset-policy.md(the tests use xorshift noise)build.rs, git hook,.cargoconfig, CI change or script (or an issue explains why)cargo test --workspacepasses (onlyviport-formatson Linux, see below)cargo clippy --workspace --all-targets --locked -- -D warningspasses (forviport-formats, see below)rustfmt; I did not reformat lines I did not changeWhat I ran
On Linux, Rust 1.98.1:
cargo test -p viport-formats --locked: 45 passed, 0 failed, 6 ignored.xma::tests::noise_frames_with_bit_counts_past_the_data has been running for over 60 seconds, and it was still running whentimeout 150killed it. With the fix, all four noise tests pass in 0.13 s.cargo clippy -p viport-formats --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run: the game, or real XMA streams. This is pure Rust with no Windows-specific code.
Overlaps
None. No open PR touches
xma.rs.🤖 Generated with Claude Code