forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode_packet.rs33 lines, 1.2 KiBHistoryRawDownload
1#![no_main]
2
3// Input layout:
4// byte 0 bit 0: channels (0 = mono, 1 = stereo); bits 1..3: output rate index
5// (mod 5: 8, 12, 16, 24, 48 kHz)
6// then packets, each prefixed by a u16 big-endian length
7// (a length past the end of the input is clamped to what remains)
8// All packets are decoded in sequence on one decoder, so state carries across them.
9
10use ec_opus::Decoder;
11use libfuzzer_sys::fuzz_target;
12
13const RATES: [u32; 5] = [8_000, 12_000, 16_000, 24_000, 48_000];
14
15fuzz_target!(|data: &[u8]| {
16 let Some((&cfg, mut rest)) = data.split_first() else {
17 return;
18 };
19 let channels = 1 + (cfg & 1) as usize;
20 let rate = RATES[((cfg >> 1) % 5) as usize];
21 let Ok(mut dec) = Decoder::new(rate, channels) else {
22 return;
23 };
24 // 120 ms at 48 kHz is the largest output one packet can produce.
25 let mut out = vec![0f32; 5760 * channels];
26 while rest.len() >= 2 {
27 let len = u16::from_be_bytes([rest[0], rest[1]]) as usize;
28 rest = &rest[2..];
29 let (pkt, tail) = rest.split_at(len.min(rest.len()));
30 let _ = dec.decode_float(pkt, &mut out);
31 rest = tail;
32 }
33});