Skip to content

Commit 600c75c

Browse files
baylesjpdeljanov
authored andcommitted
flac: Fix validation checks found by fuzzing. (#438)
This commit adds validation checks to the FLAC decoder to prevent potential panics or invalid behavior when processing malformed streams. - Verify frame channel count matches the stream information. - Ensure dropped bits per sample does not exceed frame bits per sample. - Validate that the predictor order does not exceed the block size.
1 parent 2675f10 commit 600c75c

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

symphonia-bundle-flac/src/decoder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ fn read_subframe<B: ReadBitsLtr>(bs: &mut B, frame_bps: u32, buf: &mut [i32]) ->
358358
// bits per sample in the audio sub-block. If the bit is set, unary decode the number of
359359
// dropped bits per sample.
360360
let dropped_bps = if bs.read_bool()? { bs.read_unary_zeros()? + 1 } else { 0 };
361+
if dropped_bps > frame_bps {
362+
return decode_error(
363+
"flac: dropped bits per sample is greater than the frame bits per sample",
364+
);
365+
}
361366

362367
// The bits per sample stated in the frame header is for the decoded audio sub-block samples.
363368
// However, it is likely that the lower order bits of all the samples are simply 0. Therefore,
@@ -417,6 +422,10 @@ fn decode_fixed_linear<B: ReadBitsLtr>(
417422
order: u32,
418423
buf: &mut [i32],
419424
) -> Result<()> {
425+
if order as usize > buf.len() {
426+
return decode_error("flac: fixed predictor order is greater than the block size");
427+
}
428+
420429
// The first `order` samples are encoded verbatim to warm-up the LPC decoder.
421430
decode_verbatim(bs, bps, &mut buf[..order as usize])?;
422431

@@ -434,6 +443,10 @@ fn decode_fixed_linear<B: ReadBitsLtr>(
434443
}
435444

436445
fn decode_linear<B: ReadBitsLtr>(bs: &mut B, bps: u32, order: u32, buf: &mut [i32]) -> Result<()> {
446+
if order as usize > buf.len() {
447+
return decode_error("flac: predictor order is greater than the block size");
448+
}
449+
437450
// The order of the Linear Predictor should be between 1 and 32.
438451
debug_assert!(order > 0 && order <= 32);
439452

0 commit comments

Comments
 (0)