Skip to content

Commit 0fd8815

Browse files
committed
Return "unsupported" on header without bps data
There was a to do for this already, but an option unwrap, instead of returning an error. Panics are for bugs in code. This case is not a programming error, it is just not implemented. So return the "unsupported" error. This issue was discovered by libfuzzer with cargo-fuzz.
1 parent 5bd64c7 commit 0fd8815

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/frame.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use std::i32;
1111

1212
use crc::{Crc8Reader, Crc16Reader};
13-
use error::{Result, fmt_err};
13+
use error::{Error, Result, fmt_err};
1414
use input::{Bitstream, ReadBytes};
1515
use subframe;
1616

@@ -650,9 +650,12 @@ impl<R: ReadBytes> FrameReader<R> {
650650
let total_samples = header.channels() as usize * header.block_size as usize;
651651
buffer = ensure_buffer_len(buffer, total_samples);
652652

653-
// TODO: if the bps is missing from the header, we must get it from
654-
// the streaminfo block.
655-
let bps = header.bits_per_sample.unwrap();
653+
let bps = match header.bits_per_sample {
654+
Some(x) => x,
655+
// TODO: if the bps is missing from the header, we must get it from
656+
// the streaminfo block.
657+
None => return Err(Error::Unsupported("header without bits per sample info")),
658+
};
656659

657660
// The number of bits per sample must not exceed 32, for we decode into
658661
// an i32. TODO: Turn this into an error instead of panic? Or is it

0 commit comments

Comments
 (0)