Skip to content

Commit

Permalink
Explicitly allow overflow on subtract
Browse files Browse the repository at this point in the history
This does not happen for valid FLAC files, but the library should not
panic in debug mode.

Found using libfuzzer and cargo-fuzz.
  • Loading branch information
ruuda committed Feb 22, 2017
1 parent 7e26815 commit 483eda3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,11 @@ fn decode_left_side(buffer: &mut [i32]) {
let side = *snd;

// Left is correct already, only the right channel needs to be decoded.
// side = left - right => right = left - side.
let right = left - side;
// side = left - right => right = left - side. A valid FLAC file will
// never overflow here. If we do have an overflow then we decode
// garbage, but at least Rust does not panic in debug mode due to
// overflow.
let right = left.wrapping_sub(side);
*snd = right;
}
}
Expand Down
Binary file not shown.

0 comments on commit 483eda3

Please sign in to comment.