Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/xcl/src/hle/xma2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down
Loading