forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli4 days ago4021 commits

rle.rs45 lines, 1.6 KiBHistoryRawDownload
1#![no_main]
2
3use ec_pgs::{PgsDecoder, SEG_END, SEG_ODS, SEG_PCS, SEG_PDS};
4use libfuzzer_sys::fuzz_target;
5
6// The RLE bitmap in isolation. A display set is built around the input: a canvas and one object
7// whose declared width and height come from the first four bytes, its data is the rest. Then the
8// decoder runs it. Bitmaps past the object limit are refused, the rest decode or are dropped.
9fn segment(kind: u8, body: &[u8]) -> Vec<u8> {
10 let mut out = b"PG".to_vec();
11 out.extend_from_slice(&[0; 8]);
12 out.push(kind);
13 out.extend_from_slice(&(body.len() as u16).to_be_bytes());
14 out.extend_from_slice(body);
15 out
16}
17
18fuzz_target!(|data: &[u8]| {
19 if data.len() < 4 {
20 return;
21 }
22 let width = u16::from_be_bytes([data[0], data[1]]);
23 let height = u16::from_be_bytes([data[2], data[3]]);
24 let rle = &data[4..];
25 // Palette: entry 0 clear, entry 1 opaque white. The composition is 1920x1080.
26 let pcs = [0x07, 0x80, 0x04, 0x38, 0x10, 0, 0, 0x80, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0];
27 let pds = [0, 0, 1, 235, 128, 128, 255];
28 let mut ods = vec![0, 0, 0, 0xC0];
29 ods.extend_from_slice(&((rle.len() + 4) as u32).to_be_bytes()[1..]);
30 ods.extend_from_slice(&width.to_be_bytes());
31 ods.extend_from_slice(&height.to_be_bytes());
32 ods.extend_from_slice(rle);
33 let stream = [
34 segment(SEG_PCS, &pcs),
35 segment(SEG_PDS, &pds),
36 segment(SEG_ODS, &ods),
37 segment(SEG_END, &[]),
38 ]
39 .concat();
40 let mut decoder = PgsDecoder::new();
41 let _ = decoder.push(&stream);
42 while let Some(frame) = decoder.take_frame() {
43 std::hint::black_box((frame.width, frame.height));
44 }
45});