forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode.rs31 lines, 1.0 KiBHistoryRawDownload
1#![no_main]
2
3// Untrusted entry: arbitrary bytes pushed into the MP1/MP2/MP3 byte-stream reader in chunks
4// sized by the first byte, then every frame is decoded until the reader reports an error or
5// runs dry. Errors are expected for malformed input; only panics, hangs and OOM count.
6
7use ec_mp3::Mp3Reader;
8use libfuzzer_sys::fuzz_target;
9
10/// Harness cap: frames decoded per input. A Layer III frame is 1152 samples, so this bounds
11/// the work per input without starving the reader of resync and reservoir paths.
12const MAX_FRAMES: usize = 512;
13
14fuzz_target!(|data: &[u8]| {
15 let Some((&sel, rest)) = data.split_first() else {
16 return;
17 };
18 let chunk = 1 + usize::from(sel) * 13;
19 let mut reader = Mp3Reader::new();
20 let mut frames = 0;
21 for piece in rest.chunks(chunk) {
22 reader.push(piece);
23 while let Ok(frame) = reader.next_frame() {
24 std::hint::black_box(frame);
25 frames += 1;
26 if frames == MAX_FRAMES {
27 return;
28 }
29 }
30 }
31});