XAudio2 / Opus: single length-prefixed packet misread as raw RFC 6716, 6.1 mapping stream count, and MFT output checks #327
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#327
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@mastrr9 on GitHub · 2026-11-23 23:29 UTC · original
Static audit of
crates/xcl/src/hle/opus.rsonmain(85bdf21) found three bugs on the XAudio2 Opus path (independent ofxapu/ #294):Single unpadded
[u16 LE len][pkt]buffer misread as raw RFC 6716 (opus.rs:734-739)split_packetsprefersparse_packet(data, multistream)over an exact-fit single length-prefixed packet when there is no zero-padded tail.parse_packettreats the 2-byte length prefix as the TOC + first payload byte, almost any length passes (len % 4 == 0-> code 0;1-> code 1;2-> code 2 withlen1 = 0;3-> code 3 for high byte1..=47).[0x50, 0x00] ++ <80-byte 0xF8 CELT packet>has an exact-fit prefix (len == 80 == data.len() - 2), yetparse_packet(data)reads TOC0x50(SILK WB 40 ms, code 0) and accepts all 82 bytes as one raw packet, causing garbled decode and a wrongestimate_buffer_framescount (1920instead of960).try_length_prefixed_blockfinds an exact-fit single packet (len == data.len() - 2) whose inner packet parses cleanly, prefer the length-prefixed interpretation (or pass an explicit framing hint from the caller). Add a unit test covering[0x50, 0x00] ++ <80-byte 0xF8>.7-channel (6.1) Vorbis channel mapping stream count (
opus.rs:410)vorbis_mapping(7)returnsSome((4, 3, &[0, 4, 1, 2, 3, 5, 6]))(streams = 4, coupled = 3).(5, 2, &[0, 4, 1, 2, 3, 5, 6])(2 coupled pairs + 3 uncoupled = 5 streams, 7 channels).MftDecoder::configure_output/drain_outputguards (opus.rs:951-965, 1077-1080)configure_outputaccepts the first PCM16/Float32 output type without checkingch == self.channelsand overwritesself.channels, which can cause an out-of-bounds panic during multistream interleaving if the MFT enumerates a different channel count first.drain_outputretriesMF_E_TRANSFORM_STREAM_CHANGEin an unbounded loop; capping retries (e.g. 4) avoids hanging on a misbehaving MFT.Not tested: on Windows (static code audit + clean-room Python RFC 6716 verification on macOS; no game files).
AI use: Audited with Antigravity (Gemini 4 Neon) and Claude Opus 5.5 (static code review only).
github-bot referenced this issue2026-11-26 04:23:45 +00:00
github-bot referenced this issue2026-11-26 04:59:09 +00:00
@DavidM1911 on GitHub · 2026-11-24 00:48 UTC · original
Tried item 1 on a branch: prefer the length-prefixed reading whenever
try_length_prefixed_blockreturns a clean single packet. It fixes the reported case ([0x50,0x00] ++ <0xF8 packet>now yields the 80-byte inner packet), but it also flips an existing assertion inframing_detection_awc_blocks_and_raw: thetrickybuffer[0xF8,0x00] ++ 248 zero bytesis genuinely ambiguous — as raw it is a valid CELT packet, and as[u16 len=248][packet]the inner 248 bytes also parse (TOC0x00).So the two interpretations cannot be separated by "inner parses cleanly" alone; whichever rule is chosen has to pick a side on that shape. Options I see: (a) prefer length-prefixed only when the caller knows the buffer is AWC-framed (an explicit framing hint, as the issue suggests —
extract_packetscallers in the XAudio2 path may know the submit format); (b) prefer raw when the first byte is a plausible TOC for the expected stream config; (c) accept flipping thetrickyexpectation if upstream decides single unpadded buffers are always framed. Not opening a PR until the tie-break is settled — happy to implement whichever rule you prefer.@Grimkaaah on GitHub · 2026-11-24 01:03 UTC · original
PR opened covering all three items from the issue (framing preference, 6.1 mapping, MFT channel/stream-change guards) with unit tests.
Made with Cursor
@lordon1a on GitHub · 2026-11-24 04:07 UTC · original
On item 2 of this issue and the two PRs that act on it (#503, #506): the current 6.1 mapping on
mainis already the one libopus uses, and both PRs would move it away from that.libopus
src/opus_multistream_encoder.c(currentmainof xiph/opus),vorbis_mappings[8]:So 6.1 is 4 streams / 3 coupled, exactly what
vorbis_mapping(7)returns onmain. The issue's "standard libopus / RFC 7845 6.1 mapping is(5, 2, …)" does not match libopus. With the same mapping list, (5, 2) and (4, 3) both give 7 decoded channels but group them differently: under (4, 3), centre and rear centre are one coupled stream. A multistream packet made by a libopus encoder for 7 channels has 4 streams. Split as 5 streams, the 4th self-delimited sub-packet's length is read as the start of a 5th, sosplit_multistream_packetrejects the packet or decodes the wrong bytes per channel.build_opus_headis whatDecoder::newuses when the format has noOpusHead, so that is the path a title's 6.1 Opus stream takes.vorbis_mappingand in its testvorbis_mapping_6_1_matches_rfc7845. Separately, for item 1 it changes the input of the existingframing_detection_awc_blocks_and_rawtest (tricky[1] = 0x00→0xFF). That test covered the buffer that is valid both as one raw packet and as one length-prefixed packet, which @DavidM1911 described above. With the new byte, the ambiguous case is no longer tested; the test was changed to fit the new preference. Items 1 and 3 are separate changes and would be easier to review as their own PRs, without the mapping change.I have not run a 6.1 title stream. This is from the libopus source and the packet layout, not a decode on a title. If a console-encoded 6.1 stream really is 5 / 2, the right place for that is the stream's own
OpusHead(whichparse_opus_headalready honours), not the default table.Written with Claude Code (Claude Opus 5.5). I checked the libopus table against its source.