Skip to content

Commit

Permalink
Explicitly allow wrapping when decoding mid-side
Browse files Browse the repository at this point in the history
This does not happen for valid FLAC files. For invalid files, we may
decode garbage, but that does not mean the application should crash in
debug mode. (Rust panics on overflow in debug mode.)

There were multiple overflows here, all detected by libfuzzer with
cargo-fuzz.
  • Loading branch information
ruuda committed Feb 22, 2017
1 parent aa43c6b commit 8b9a773
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,12 @@ fn decode_mid_side(buffer: &mut [i32]) {
let side = *snd;

// Double mid first, and then correct for truncated rounding that
// will have occured if side is odd.
let mid = (mid * 2) | (side & 1);
let left = (mid + side) / 2;
let right = (mid - side) / 2;
// will have occured if side is odd. Note that samples are never
// expected to exceed 25 bits, so the wrapping multiplication does not
// actually wrap for valid files.
let mid = mid.wrapping_mul(2) | (side & 1);
let left = mid.wrapping_add(side) / 2;
let right = mid.wrapping_sub(side) / 2;

*fst = left;
*snd = right;
Expand Down

0 comments on commit 8b9a773

Please sign in to comment.