forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode.rs48 lines, 1.9 KiBHistoryRawDownload
1#![no_main]
2
3// Input layout:
4// byte 0 selects one of three fixed header sets (mod 3): mono, stereo, 5.1 at 48 kHz,
5// each embedded from fixtures/audio via include_bytes! (see fuzz/seed.sh)
6// then audio packets, each prefixed by a u16 big-endian length (a length past the end
7// is clamped to what remains), decoded in sequence on one decoder.
8
9use ec_vorbis::VorbisDecoder;
10use libfuzzer_sys::fuzz_target;
11
12// Each blob is three u16-BE-length-prefixed header packets: identification, comment, setup.
13const MONO: &[u8] = include_bytes!("../headers/mono-48k.bin");
14const STEREO: &[u8] = include_bytes!("../headers/stereo-48k.bin");
15const SURROUND: &[u8] = include_bytes!("../headers/surround-48k.bin");
16
17/// Split `data` into u16-BE-length-prefixed packets, at most `max` of them.
18fn chunks(mut data: &[u8], max: usize) -> Vec<&[u8]> {
19 let mut out = Vec::new();
20 while out.len() < max && data.len() >= 2 {
21 let len = u16::from_be_bytes([data[0], data[1]]) as usize;
22 let (packet, tail) = data[2..].split_at(len.min(data.len() - 2));
23 out.push(packet);
24 data = tail;
25 }
26 out
27}
28
29fuzz_target!(|data: &[u8]| {
30 let Some((&sel, rest)) = data.split_first() else {
31 return;
32 };
33 // Harness cap: at most 4 KiB of packets and 8 packets per input. Uncapped, the seeds (up to
34 // 62 KB of packets) ran at about 16 exec/s. Capped: 66 exec/s in a 60 s probe, 33 exec/s
35 // averaged over the hour-long run on a shared host.
36 let rest = &rest[..rest.len().min(4096)];
37 let blob = match sel % 3 {
38 0 => MONO,
39 1 => STEREO,
40 _ => SURROUND,
41 };
42 // The blobs are constants, so a failure here is a harness bug, not an input finding.
43 let headers = chunks(blob, 3);
44 let mut dec = VorbisDecoder::new(&headers).expect("built-in Vorbis headers must parse");
45 for packet in chunks(rest, 8) {
46 let _ = dec.decode_audio(packet);
47 }
48});