forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

compose.rs31 lines, 1.3 KiBHistoryRawDownload
1#![no_main]
2
3use ec_pgs::{PgsDecoder, SEG_END, SEG_ODS, SEG_PCS, SEG_PDS, SEG_WDS};
4use libfuzzer_sys::fuzz_target;
5
6// Composition from structured segments. The input is read as a list of (kind, length, body)
7// records: the kind byte picks PCS, WDS, PDS, ODS or END, the length byte gives the body size, and
8// the body is the next bytes of input. Each record is framed as a valid `.sup` segment, so the
9// bodies (canvas size, placement, window, palette and object fields) reach the composer every time.
10fuzz_target!(|data: &[u8]| {
11 const KINDS: [u8; 5] = [SEG_PCS, SEG_WDS, SEG_PDS, SEG_ODS, SEG_END];
12 let mut stream = Vec::new();
13 let mut at = 0;
14 while at + 2 <= data.len() {
15 let kind = KINDS[usize::from(data[at]) % KINDS.len()];
16 let len = usize::from(data[at + 1]);
17 at += 2;
18 let body = &data[at..(at + len).min(data.len())];
19 at += body.len();
20 stream.extend_from_slice(b"PG");
21 stream.extend_from_slice(&[0; 8]);
22 stream.push(kind);
23 stream.extend_from_slice(&(body.len() as u16).to_be_bytes());
24 stream.extend_from_slice(body);
25 }
26 let mut decoder = PgsDecoder::new();
27 let _ = decoder.push(&stream);
28 while let Some(frame) = decoder.take_frame() {
29 std::hint::black_box((frame.width, frame.height));
30 }
31});