forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode_frame.rs53 lines, 1.8 KiBHistoryRawDownload
1#![no_main]
2
3use ec_flac::decode::{Block, ChannelAssignment};
4use ec_flac::{FlacReader, StreamInfo};
5use libfuzzer_sys::fuzz_target;
6
7// Byte 0 selects a fixed STREAMINFO (as a container would carry it); the rest is
8// bare frames, handed to `next_block` one call at a time.
9fuzz_target!(|data: &[u8]| {
10 let Some((&sel, frames)) = data.split_first() else {
11 return;
12 };
13 // Harness cap: at most 16 KiB of frame data per input. The seeds run to 950 KB, and
14 // uncapped the target ran at about 31 exec/s.
15 let frames = &frames[..frames.len().min(16 * 1024)];
16 let (sample_rate, channels, bits_per_sample) = match sel % 5 {
17 0 => (44_100, 2, 16),
18 1 => (48_000, 1, 24),
19 2 => (96_000, 2, 32),
20 3 => (22_050, 8, 8),
21 _ => (192_000, 6, 12),
22 };
23 let info = StreamInfo {
24 min_block_size: 16,
25 max_block_size: 4096,
26 min_frame_size: 0,
27 max_frame_size: 0,
28 sample_rate,
29 channels,
30 bits_per_sample,
31 total_samples: 0,
32 md5: [0; 16],
33 };
34 let Ok(mut reader) = FlacReader::frames(frames, Some(info)) else {
35 return;
36 };
37 let mut block = Block::default();
38 // Bounded by the input: every decoded frame consumes at least its header.
39 while let Ok(true) = reader.next_block(&mut block) {
40 if let Some(h) = block.header {
41 // Frame decode must agree with the header it was built from.
42 assert_eq!(block.channels.len(), h.channels.channel_count());
43 assert!(matches!(
44 h.channels,
45 ChannelAssignment::Independent(_)
46 | ChannelAssignment::LeftSide
47 | ChannelAssignment::RightSide
48 | ChannelAssignment::MidSide
49 ));
50 assert!(block.channels.iter().all(|c| c.len() == h.block_size));
51 }
52 }
53});