forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode_mpeg4.rs53 lines, 1.6 KiBHistoryRawDownload
1#![no_main]
2
3// Untrusted entry: arbitrary bytes fed to the MPEG-4 Part 2 / H.263 byte-stream API in
4// random-sized chunks, then flushed and drained. Errors are expected for malformed input;
5// only panics, hangs and OOM count. The first input byte picks the FourCC-less default,
6// DivX or XviD IDCT forcing, so both IDCT paths are reached.
7
8use ec_core::registry::{CodecId, CodecParameters};
9use ec_mpeg4::Mpeg4Decoder;
10use libfuzzer_sys::fuzz_target;
11
12fn drain(dec: &mut Mpeg4Decoder) {
13 while let Some(p) = dec.pop_picture() {
14 std::hint::black_box(p);
15 }
16}
17
18fuzz_target!(|data: &[u8]| {
19 let Ok(mut dec) = Mpeg4Decoder::new(CodecParameters::new(CodecId::Mpeg4Part2)) else {
20 return;
21 };
22 let Some((&mode, data)) = data.split_first() else {
23 return;
24 };
25 match mode & 3 {
26 1 => dec.set_xvid_idct(Some(true)),
27 2 => dec.set_xvid_idct(Some(false)),
28 _ => {}
29 }
30 let mut s = 0x9E37_79B9_7F4A_7C15u64 ^ data.len() as u64;
31 for &b in data.iter().take(8) {
32 s = s.rotate_left(8) ^ u64::from(b);
33 }
34 let mut rest = data;
35 while !rest.is_empty() {
36 s ^= s << 13;
37 s ^= s >> 7;
38 s ^= s << 17;
39 let n = match s % 4 {
40 0 => 1 + (s >> 8) as usize % 8,
41 1 => 1 + (s >> 8) as usize % 64,
42 2 => 1 + (s >> 8) as usize % 1024,
43 _ => rest.len(),
44 }
45 .min(rest.len());
46 let (chunk, tail) = rest.split_at(n);
47 rest = tail;
48 let _ = dec.send_bytes(chunk, None);
49 drain(&mut dec);
50 }
51 let _ = dec.flush_stream();
52 drain(&mut dec);
53});