Formats/XMA: treat PacketSkipCount 0xff as end of stream #3223
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!3223
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3223"
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?
@fuzeofficlal on GitHub · 2026-11-26 13:39 UTC · original
fuzeofficlal:fix/xma-packet-skip-eos→main· +151 −4 · 1 files · 1 commits · closed without mergingSummary
PacketSkipCountis0xff(255), the end-of-stream sentinel in the XMA2 packet header specification (XMA2PACKET::PacketSkipCount).Cursor::bitandnext_frameadded0xffliterally as a 255-packet skip, causing streams ending withskip == 0xffinside buffers longer than 256 packets to jump 256 packets ahead into another interleaved stream's packets instead of terminating.Changes
crates/victory-formats/src/xma.rs:END_OF_STREAM = 0xffand addPacket::next(self, index) -> Option<usize>, returningNoneon0xffandindex + 1 + skip(checked) for0x00..=0xfe.Packet::nextinCursor::bitandnext_frame(including theframes == 0continuation-packet loop). Frames contained inside the final0xffpacket (including one ending right at the packet edge) still decode normally before returningnext: None.0xfffinal packets,frames == 0continuation packets / cursor boundary reads on0xff, and the maximum non-sentinel skip0xfe(254) as a negative control.Verification
cargo test -p victory-formats --locked: 49 passed, 0 failed, 5 ignoredcargo test -p victory-formats --release --locked: 49 passed, 0 failed, 5 ignoredcargo test -p victory-hle --locked audio: 8 passed, 0 failedcargo clippy --workspace --all-targets --locked -- -D warnings: passedcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passedcargo test -p xtask --locked policy::tests::repository_passes_policy: passed@AurumCarlos on GitHub · 2026-11-26 13:51 UTC · original · reviewed
The code change is tidy. Routing every skip through
Packet::nextmeans the three places that usedskip(Cursor::bitwhen leaving a packet, the first hop innext_frame, and itsframes == 0walk) all stop on the sentinel the same way, and the index arithmetic is now overflow-checked as a bonus. I didn't find any other reader ofPacket::skip:audio.rsonly usesfirst_frame_bitfromxma::packet. The tests cover the right corners: a final packet with two frames, a frame ending exactly on the packet edge, a continuation-only packet, a chain of them, a payload read that would cross the end, and0xfestill skipping 254 packets.One thing I'd like to see in the description: where the
0xff= end-of-stream rule comes from. It cites "the XMA2 packet header specification (XMA2PACKET::PacketSkipCount)" but gives no link or quote. Without the sentinel rule, 255 reads like an ordinary skip count. A stream's next packet can legitimately be far away when other streams use more packets in between, so the change rests entirely on that rule. A pointer to the header comment inxma2defs.h, or to another decoder that treats 255 the same way, would let a reviewer confirm it without guessing. If a decoder you checked against was the source, saying which one would help too.Nit: the "Changes" section has a bullet for
xma.rswith nothing after it.@cloph-dsp on GitHub · 2026-11-26 13:59 UTC · original
Independent local verification of head
c724815on Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-formats --lib -- xma::tests::packet_skip_0xff_stops_continuation_and_spanning_reads --exact— 1 passed, 0 failed.git diff --check origin/main HEAD— clean used a worktree-localCARGO_TARGET_DIR.Synthetic XMA packet words only; no game audio, extracted assets or DRM material used. AI-assisted (Hy4 flash). GPU/driver N/A (CPU-only formats crate).
@Dukestar69 on GitHub · 2026-11-26 14:12 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:20 UTC · original
I ran the three new packet-walking tests from
c724815on Windows. With the same tests transplanted ontomain(63bcca4), all three fail at the0xfftermination assertions. The0xfecase successfully reaches packet 255 on both revisions and differs at the following0xff. On the PR head all three pass, and the formats suite is 49 passed, 5 ignored.For the source question in the review, vgmstream's XMA2 sample counter gives
0xffspecial handling as a full-packet skip. Its loop resumes at the next physical packet. FFmpeg's packet parser counts the byte literally. The synthetic tests pin the behavior this PR proposes. The console contract for a packet carrying both0xffand new frame starts remains unverified in these sources.Can you link the exact specification passage or share a native decoder result for that case? That would settle the remaining review question.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:25 UTC · original
I ran the three packet-skip tests on main
63bcca4with only your test hunk applied and on exact headc724815. The tests went from 0/3 to 3/3 on Windows/MSVC. On main the final packet in the two-frame case incorrectly reports packet 256 as its next frame. The0xfecontrol still reaches packet 255 and preserves the spanning payload with the patch. The full formats lib suite passed 49 (5 ignored), the HLE audio subset passed 8/8, and strict formats Clippy passed. Fixtures were synthetic.Could you link the
XMA2PACKET::PacketSkipCountreference or share a hardware result for a full-skip packet followed by a normal packet in the same input buffer? The patches and tests establish the behavior change. The end-of-stream rule is the part that needs a format or hardware reference. Xenia Canary advances to the next sequential packet for a full-skip packet at the current read position and stops its continuation walk on that same value. vgmstream describes0xffas a full skip with no new frame starts, where a previous frame can end. Xenia current packet, Xenia continuation, vgmstream packet headerAI-assisted with Codex.
@fuzeofficlal on GitHub · 2026-11-26 16:46 UTC · original
Thank you both (@AurumCarlos and @andrewpozdnakov7-jpg) for pressing for a primary source here.
After re-checking Microsoft's
xma2defs.h(GetXmaFrameBitPosition/GetLastXmaFrameBitPosition),hcs64/xma_parse, FFmpeg (xma_parser.c/wmaprodec.c),vgmstream(coding_utils.c), and Xenia (xma_context_new.cc/ upstreamxma_context.cc), I cannot substantiatePacketSkipCount == 0xffas a documented end-of-stream sentinel after decoding new frames in that packet:xma2defs.h,xma_parse, FFmpeg, and upstream Xenia all treatPacketSkipCountliterally (skip + 1) and only special-case0x7FFFforFrameOffsetInBits/LengthInBits.vgmstreamand Xenia Canary (470e62af) special-case0xFFas a full packet skip (assuming no new frames start in the packet and advancing to the next physical packet), which is a different contract from decoding frames in a0xFFpacket and then terminating the stream.Without a primary specification or hardware capture proving EOS semantics for
0xFF, this change shouldn't land. Closing this PR rather than leaving an unverified format assumption open.Pull request closed