forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

fuzz_regressions.rs28 lines, 1.3 KiBHistoryRawDownload
1//! Replays of inputs that the fuzzer found to crash the Opus decoder. The input is replayed
2//! with the same framing as the `decode_packet` harness, and with no harness caps.
3
4use ec_opus::Decoder;
5
6/// `decode_packet` panic: the CELT path calls `tell_frac` after `skip_to_end` on a frame of a
7/// few bytes. The bit count then dips below zero, and the unsigned subtraction in
8/// `RangeDecoder::tell_frac` panicked in debug builds (wrapped in release). The decode must now
9/// finish without panicking, whatever it returns.
10#[test]
11fn silent_celt_frame_tell_frac_does_not_underflow() {
12 let data: &[u8] = include_bytes!("data/fuzz/decode_packet-tell-frac-underflow.bin");
13 let Some((&cfg, mut rest)) = data.split_first() else {
14 panic!("replay input is empty");
15 };
16 let channels = 1 + (cfg & 1) as usize;
17 const RATES: [u32; 5] = [8_000, 12_000, 16_000, 24_000, 48_000];
18 let rate = RATES[((cfg >> 1) % 5) as usize];
19 let mut dec = Decoder::new(rate, channels).expect("replay rate and channel count are valid");
20 let mut out = vec![0f32; 5760 * channels];
21 while rest.len() >= 2 {
22 let len = u16::from_be_bytes([rest[0], rest[1]]) as usize;
23 rest = &rest[2..];
24 let (pkt, tail) = rest.split_at(len.min(rest.len()));
25 let _ = dec.decode_float(pkt, &mut out);
26 rest = tail;
27 }
28}