Skip to content

Commit

Permalink
Return "unsupported" on header without bps data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ruuda committed Feb 22, 2017
1 parent 5bd64c7 commit 0fd8815
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use std::i32;

use crc::{Crc8Reader, Crc16Reader};
use error::{Result, fmt_err};
use error::{Error, Result, fmt_err};
use input::{Bitstream, ReadBytes};
use subframe;

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

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

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

0 comments on commit 0fd8815

Please sign in to comment.