forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

parse_sync.rs34 lines, 1.3 KiBHistoryRawDownload
1#![no_main]
2
3use ec_truehd::{AccessUnitHeader, frame_length};
4use libfuzzer_sys::fuzz_target;
5
6/// TrueHD major sync word, `0xF8726FBA`.
7const MAJOR_SYNC_TRUEHD: [u8; 4] = [0xF8, 0x72, 0x6F, 0xBA];
8
9/// Largest body that keeps the whole access unit within the 12-bit length word
10/// (8190 bytes = 4095 words): 8190 - 4-byte AU header - 4-byte sync word.
11const MAX_BODY: usize = 8190 - 8;
12
13fuzz_target!(|data: &[u8]| {
14 // Raw bytes: the length word and, if it happens to match, the major sync.
15 let _ = frame_length(data);
16 let _ = AccessUnitHeader::parse(data);
17
18 // Fixup: wrap the input in a valid AU header and TrueHD major sync word, so the
19 // mutations land on the sync fields and the directory behind them instead of on
20 // the 4 sync bytes. The length word is set to the wrapped buffer's length.
21 let body = &data[..data.len().min(MAX_BODY)];
22 let mut au = Vec::with_capacity(8 + body.len() + 1);
23 au.extend_from_slice(&[0, 0, 0, 0]);
24 au.extend_from_slice(&MAJOR_SYNC_TRUEHD);
25 au.extend_from_slice(body);
26 if au.len() % 2 != 0 {
27 au.push(0);
28 }
29 let Ok(words) = u16::try_from(au.len() / 2) else {
30 return;
31 };
32 au[..2].copy_from_slice(&(words & 0x0FFF).to_be_bytes());
33 let _ = AccessUnitHeader::parse(&au);
34});