Skip to content

Commit ad975ef

Browse files
committed
aac: add validation for Ics.info.max_sfb, fixes out of range panic during decoding.
1 parent 975484c commit ad975ef

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

symphonia-codec-aac/src/aac/cpe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl ChannelPair {
5959

6060
if common_window {
6161
// Decode the common ICS info block into the first channel.
62-
self.ics0.info.decode(bs)?;
62+
// do not call self.ics0.info.decode() as it will skip required validations present in self.ics0.decode_info()
63+
self.ics0.decode_info(bs)?;
6364

6465
// Mid-side stereo mask decoding.
6566
self.ms_mask_present = bs.read_bits_leq32(2)? as u8;

symphonia-codec-aac/src/aac/ics/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl IcsInfo {
106106
}
107107
}
108108

109+
/// this method should be called from Ics::decode_info() which will perform additional validations for max_sfb
109110
pub fn decode<B: ReadBitsLtr>(&mut self, bs: &mut B) -> Result<()> {
110111
self.prev_window_sequence = self.window_sequence;
111112
self.prev_window_shape = self.window_shape;
@@ -291,6 +292,16 @@ impl Ics {
291292
self.sfb_cb[g][sfb] == INTENSITY_HCB
292293
}
293294

295+
pub fn decode_info<B: ReadBitsLtr>(&mut self, bs: &mut B) -> Result<()> {
296+
self.info.decode(bs)?;
297+
298+
// validate info.max_sfb - it should not be bigger than bands array len - 1
299+
if self.info.max_sfb + 1 > self.get_bands().len() {
300+
return decode_error("aac: ics info max_sfb is too big for the bands size");
301+
}
302+
Ok(())
303+
}
304+
294305
fn decode_scale_factor_data<B: ReadBitsLtr>(&mut self, bs: &mut B) -> Result<()> {
295306
let mut noise_pcm_flag = true;
296307
let mut scf_intensity = -INTENSITY_SCALE_MIN;
@@ -407,7 +418,8 @@ impl Ics {
407418

408419
// If a common window is used, a common ICS info was decoded previously.
409420
if !common_window {
410-
self.info.decode(bs)?;
421+
// do not call self.info.decode() as it will skip required validations present in the decode_info()
422+
self.decode_info(bs)?;
411423
}
412424

413425
self.decode_section_data(bs)?;

0 commit comments

Comments
 (0)