forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

setup.rs36 lines, 1.3 KiBHistoryRawDownload
1#![no_main]
2
3// Input layout:
4// three packets, each prefixed by a u16 big-endian length: identification, comment, setup.
5// A length past the end of the input is clamped to what remains. Extra bytes after the third
6// packet are ignored.
7
8use ec_vorbis::{Comments, Identification, VorbisDecoder};
9use libfuzzer_sys::fuzz_target;
10
11/// Split `data` into at most `max` u16-BE-length-prefixed packets.
12fn chunks(mut data: &[u8], max: usize) -> Vec<&[u8]> {
13 let mut out = Vec::new();
14 while out.len() < max && data.len() >= 2 {
15 let len = u16::from_be_bytes([data[0], data[1]]) as usize;
16 let (packet, tail) = data[2..].split_at(len.min(data.len() - 2));
17 out.push(packet);
18 data = tail;
19 }
20 out
21}
22
23fuzz_target!(|data: &[u8]| {
24 let parts = chunks(data, 3);
25 // Each parser on its own first, then all three together through the public decoder
26 // constructor, which runs Setup::parse against the parsed identification header.
27 if let Some(ident) = parts.first() {
28 let _ = Identification::parse(ident);
29 }
30 if let Some(comment) = parts.get(1) {
31 let _ = Comments::parse(comment);
32 }
33 if let [ident, comment, setup] = parts.as_slice() {
34 let _ = VorbisDecoder::new(&[*ident, *comment, *setup]);
35 }
36});