XMA: end a frame at its data instead of looping forever (port of VIctory#183) #40

Manually merged
github merged 1 commit from gh-pr/40/head into gh-pr/40/base 2026-11-26 03:42:09 +00:00
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:08 UTC · original
lcg007xd-c:port/xma-noise-hang → main · +238 −1 · 1 files · 1 commits · merged 2026-11-25 20:33 UTC

Port of Marvisak/VIctory#183 by AnoHunted, cherry-picked with -x, so the commit keeps its author. VItoriaBr's issue #4 lists 338808e as a sync candidate, but main doesn't have it yet.

What it fixes

Decoder::decode bounds a frame by its header's bit count, not by the bytes it was given. A frame whose bit count runs past the data loops forever. The fix is one line in crates/victory-formats/src/xma.rs (end: bits.min(data.len().saturating_mul(8))). The rest is upstream's noise tests.

In the game, victory-hle's caller passes frame.bits from read_frame, so this hardens the decoder against bad streams. I haven't seen it hang in a real run.

Tested (Linux, Rust 1.98.1)

  • The picked commit applies to main without conflicts.
  • cargo test -p victory-formats --locked xma: 10 passed, 2 ignored.
  • With the old line put back, noise_frames_with_bit_counts_past_the_data hangs: still running after 60 s, killed at 120 s.
  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings: clean.

Note: until #39 is in, the portable CI job stays red for an unrelated reason (an unused variable in the POPS test).

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/40) `lcg007xd-c:port/xma-noise-hang` → `main` · +238 −1 · 1 files · 1 commits · merged 2026-11-25 20:33 UTC Port of [Marvisak/VIctory#183](https://github.com/Marvisak/VIctory/pull/183) by AnoHunted, cherry-picked with `-x`, so the commit keeps its author. VItoriaBr's issue #4 lists `338808e` as a sync candidate, but `main` doesn't have it yet. ## What it fixes `Decoder::decode` bounds a frame by its header's bit count, not by the bytes it was given. A frame whose bit count runs past the data loops forever. The fix is one line in `crates/victory-formats/src/xma.rs` (`end: bits.min(data.len().saturating_mul(8))`). The rest is upstream's noise tests. In the game, `victory-hle`'s caller passes `frame.bits` from `read_frame`, so this hardens the decoder against bad streams. I haven't seen it hang in a real run. ## Tested (Linux, Rust 1.98.1) - The picked commit applies to `main` without conflicts. - `cargo test -p victory-formats --locked xma`: 10 passed, 2 ignored. - With the old line put back, `noise_frames_with_bit_counts_past_the_data` hangs: still running after 60 s, killed at 120 s. - `cargo clippy -p victory-formats --all-targets --locked -- -D warnings`: clean. Note: until #39 is in, the portable CI job stays red for an unrelated reason (an unused variable in the POPS test). 🤖 Generated with [Claude Code](https://claude.com/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 <[email protected]>
(cherry picked from commit d4d1822049fed053c6188ea0b016b0976a71bf41)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:09 +00:00
github manually merged commit 4b37b4448c into gh-pr/40/base 2026-11-26 03:42:09 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.