From 8d0176d9b8099092d2c9809bf25630be68e7d7ee Mon Sep 17 00:00:00 2001 From: David Date: Tue, 24 Nov 2026 08:26:33 +0000 Subject: [PATCH] Opus: only take MFT output types with the decoder's channel count, cap stream-change retries configure_output accepted the first PCM16/Float32 type regardless of MF_MT_AUDIO_NUM_CHANNELS and then overwrote self.channels, so a multistream interleave could index past the buffer; drain_output retried MF_E_TRANSFORM_STREAM_CHANGE forever. Output types whose channel count differs from the decoder's are now skipped, and more than 4 stream changes is an error. --- crates/xcl/src/hle/opus.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/xcl/src/hle/opus.rs b/crates/xcl/src/hle/opus.rs index ac9c01313f..436b8d0a60 100644 --- a/crates/xcl/src/hle/opus.rs +++ b/crates/xcl/src/hle/opus.rs @@ -1153,6 +1153,11 @@ impl MftDecoder { let bits = mt.GetUINT32(&MF_MT_AUDIO_BITS_PER_SAMPLE).unwrap_or(0); let rate = mt.GetUINT32(&MF_MT_AUDIO_SAMPLES_PER_SECOND).unwrap_or(48_000); let ch = mt.GetUINT32(&MF_MT_AUDIO_NUM_CHANNELS).unwrap_or(self.channels as u32) as u16; + // The decoder interleaves `self.channels` channels; an output type with a + // different count would panic there, so only matching types are eligible. + if ch != self.channels { + continue; + } if sub == MFAudioFormat_PCM && bits == 16 { chosen = Some((mt, OutputSampleFormat::Pcm16, rate, ch)); break; @@ -1238,6 +1243,7 @@ impl MftDecoder { } unsafe fn drain_output(&mut self, rt: &MfRuntime, out: &mut Vec) -> Result<(), String> { + let mut stream_changes = 0u32; loop { let alloc_sample = if self.mft_provides_samples { None @@ -1269,6 +1275,10 @@ impl MftDecoder { } Err(e) if e.code() == MF_E_TRANSFORM_NEED_MORE_INPUT => break, Err(e) if e.code() == MF_E_TRANSFORM_STREAM_CHANGE => { + stream_changes += 1; + if stream_changes > 4 { + return Err("ProcessOutput: MF_E_TRANSFORM_STREAM_CHANGE kept coming back after reconfiguring".to_string()); + } self.configure_output()?; continue; }