From a7f5d8be9b4d131f801ca3716d9843363f4df875 Mon Sep 17 00:00:00 2001 From: hajduzsolt <66201672+hajduzsolt@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:07:54 +0100 Subject: [PATCH] XAudio2: reject invalid XMA stream channel counts Reject zero-channel and more-than-stereo streams before constructing fixed-size decoder state. Co-Authored-By: Codex GPT-6 --- crates/xcl/src/hle/xma2/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/xcl/src/hle/xma2/mod.rs b/crates/xcl/src/hle/xma2/mod.rs index b85aabd42e..fcc31eaf7a 100644 --- a/crates/xcl/src/hle/xma2/mod.rs +++ b/crates/xcl/src/hle/xma2/mod.rs @@ -1645,6 +1645,9 @@ impl Decoder { if cfg.stream_channels.is_empty() || cfg.stream_channels.len() > MAX_STREAMS { return Err(format!("invalid stream count {}", cfg.stream_channels.len())); } + if cfg.stream_channels.iter().any(|&c| c == 0 || usize::from(c) > MAX_CHANNELS_PER_STREAM) { + return Err("each XMA stream must have one or two channels".into()); + } let sum: usize = cfg.stream_channels.iter().map(|&c| c as usize).sum(); if sum == 0 || sum != cfg.channels as usize { return Err(format!("channel sum {sum} != {}", cfg.channels)); @@ -2201,6 +2204,16 @@ pub(crate) mod tests { assert!(StreamConfig::from_xma2_wfx(17, 48_000, &extra).is_err()); } + #[test] + fn decoder_rejects_invalid_per_stream_channel_counts() { + for (channels, streams) in [(2, vec![0, 2]), (3, vec![3]), (4, vec![1, 3])] { + let cfg = StreamConfig { version: Version::Xma2, sample_rate: 48_000, channels, stream_channels: streams }; + assert!(Decoder::new(cfg).is_err()); + } + let cfg = StreamConfig { version: Version::Xma1, sample_rate: 48_000, channels: 3, stream_channels: vec![2, 1] }; + assert!(Decoder::new(cfg).is_ok()); + } + #[test] fn decodes_xma2_and_xma1_bitstreams_matching_ffmpeg() { // 1. Mono 48 kHz tone (12 frames -> 6080 samples) + trailing 0xFF padding packet + flush reuse.