Skip to content

Commit 875c3b2

Browse files
committed
Return format error for >31 wasted bits per sample
Although the spec does not forbid it, it does not make sense. This issue was discovered by libfuzzer with cargo-fuzz.
1 parent cafd928 commit 875c3b2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/subframe.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ fn read_subframe_header<R: ReadBytes>(input: &mut Bitstream<R>) -> Result<Subfra
7676
1 + try!(input.read_unary())
7777
};
7878

79+
// The spec puts no bounds on the number of wasted bits per sample, but more
80+
// than 31 does not make sense, as it would remove all data even for 32-bit
81+
// samples.
82+
if wasted_bits > 31 {
83+
return fmt_err("wasted bits per sample must not exceed 31");
84+
}
85+
7986
let subframe_header = SubframeHeader {
8087
sf_type: sf_type,
8188
wasted_bits_per_sample: wasted_bits,
@@ -199,7 +206,7 @@ pub fn decode<R: ReadBytes>(input: &mut Bitstream<R>,
199206
// the left. Note: it might be better performance-wise to do this on
200207
// the fly while decoding. That could be done if this is a bottleneck.
201208
if header.wasted_bits_per_sample > 0 {
202-
debug_assert!(header.wasted_bits_per_sample < 31,
209+
debug_assert!(header.wasted_bits_per_sample <= 31,
203210
"Cannot shift by more than the sample width.");
204211
for s in buffer {
205212
// For a valid FLAC file, this shift does not overflow. For an

0 commit comments

Comments
 (0)