Skip to content

Port upstream #183: XMA ends a frame at its data instead of looping forever - #24

Merged
DesertGamer merged 1 commit into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-183-xma-end
Nov 25, 2026
Merged

DesertGamer merged 1 commit into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-183-xma-end

Conversation

@lcg007xd-c

@lcg007xd-c lcg007xd-c commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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. In crates/viport-formats/src/xma.rs, Decoder::decode still sets end: bits, where upstream has end: 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 existing stream_frame_count / counts_only_packets_in_the_selected_stream tests and put #183's tests after them. The doc comment of walks_saved_streams keeps VIPORT_XMA_STREAMS.

Checked

  • No game data of any kind (files, extracts, screenshots, dumps, saves): see docs/asset-policy.md (the tests use xorshift noise)
  • No binary files or archives
  • No new dependency, build.rs, git hook, .cargo config, CI change or script (or an issue explains why)
  • No download, no started program, no network connection added (or an issue explains why)
  • cargo test --workspace passes (only viport-formats on Linux, see below)
  • cargo clippy --workspace --all-targets --locked -- -D warnings passes (for viport-formats, see below)
  • The code I wrote is formatted with rustfmt; I did not reformat lines I did not change

What I ran

On Linux, Rust 1.98.1:

  • cargo test -p viport-formats --locked: 45 passed, 0 failed, 6 ignored.
  • Without the one-line fix, with the tests kept: xma::tests::noise_frames_with_bit_counts_past_the_data has been running for over 60 seconds, and it was still running when timeout 150 killed 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

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
lcg007xd-c force-pushed the port/upstream-183-xma-end branch from 8d26e62 to 2f0d75b Compare November 25, 2026 21:45
@DesertGamer
DesertGamer merged commit d907f57 into DesertGamer:main Nov 25, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants