forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode_avcc.rs37 lines, 1.4 KiBHistoryRawDownload
1#![no_main]
2
3// Untrusted entry: the packet-level H264Decoder as a demuxer drives it.
4// Input layout: byte 0 gives the avcC extradata length (modulo the rest),
5// the next bytes are the avcC record, and the remainder is one packet
6// (length-prefixed NAL units when the record is valid, Annex B otherwise).
7
8use ec_core::registry::{CodecId, CodecParameters, Decoder as _};
9use ec_core::{Packet, TimeBase};
10use ec_h264::H264Decoder;
11use libfuzzer_sys::fuzz_target;
12
13/// Harness caps (see lanes/fuzz1hvideo.report.md): at most 512 bytes of avcC
14/// record and 4 KiB of packet, so one exec stays small enough to run at a useful rate.
15const MAX_EXTRADATA: usize = 512;
16const MAX_PACKET: usize = 4096;
17
18fuzz_target!(|data: &[u8]| {
19 let Some((&split, rest)) = data.split_first() else {
20 return;
21 };
22 let split = usize::from(split) % (rest.len() + 1);
23 let (extradata, packet) = rest.split_at(split);
24 let extradata = &extradata[..extradata.len().min(MAX_EXTRADATA)];
25 let packet = &packet[..packet.len().min(MAX_PACKET)];
26
27 let mut params = CodecParameters::new(CodecId::H264);
28 params.extradata = Some(extradata.to_vec().into());
29 let Ok(mut decoder) = H264Decoder::new(params) else {
30 return;
31 };
32 let _ = decoder.send_packet(&Packet::new(0, TimeBase::new(1, 25), packet.to_vec()));
33 let _ = decoder.flush();
34 while let Ok(frame) = decoder.receive_frame() {
35 std::hint::black_box(frame);
36 }
37});