forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

decode_frame.rs37 lines, 1.3 KiBHistoryRawDownload
1#![no_main]
2
3use ec_vp8::decode::Decoder;
4use libfuzzer_sys::fuzz_target;
5
6/// Harness cap (see lanes/fuzz1hvideo.report.md): a key frame with luma above 128x128 is not
7/// fed. Inter frames inherit the size of the key frame before them, so the input is skipped
8/// when its own header is an oversized key frame.
9const MAX_DIM: u32 = 128;
10
11fuzz_target!(|data: &[u8]| {
12 if oversized_key_frame(data) {
13 return;
14 }
15 // One frame through a fresh decoder. Errors are the expected outcome for
16 // malformed input; the target only looks for panics, hangs and OOM.
17 let mut dec = Decoder::new();
18 let _ = dec.decode(data);
19});
20
21fn oversized_key_frame(frame: &[u8]) -> bool {
22 matches!(key_frame_dims(frame), Some((w, h)) if w > MAX_DIM || h > MAX_DIM)
23}
24
25/// Size of a key frame from its frame tag and start code (RFC 6386 9.1), or `None` for
26/// inter frames and frames too short to hold the header.
27fn key_frame_dims(frame: &[u8]) -> Option<(u32, u32)> {
28 let [tag0, _, _, 0x9d, 0x01, 0x2a, w0, w1, h0, h1, ..] = *frame else {
29 return None;
30 };
31 if tag0 & 1 != 0 {
32 return None;
33 }
34 let width = u32::from(u16::from_le_bytes([w0, w1]) & 0x3fff);
35 let height = u32::from(u16::from_le_bytes([h0, h1]) & 0x3fff);
36 Some((width, height))
37}