forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

webvtt.rs33 lines, 1.0 KiBHistoryRawDownload
1#![no_main]
2
3use ec_subs::{SubtitleTrack, plain_text, webvtt};
4use libfuzzer_sys::fuzz_target;
5
6/// Every cue the parser returns is well-formed: the end is never before the start, and the text
7/// flattens without a panic.
8fn check(track: &SubtitleTrack) {
9 for cue in &track.cues {
10 assert!(cue.end_us >= cue.start_us);
11 let _ = plain_text(&cue.segments);
12 if let Some(name) = &cue.style_ref {
13 let _ = track.style(name);
14 }
15 }
16}
17
18// WebVTT, bytes and lossy text. The `WEBVTT` header is optional in the parser, so the input is
19// also tried after a header, which reaches the cue and settings code on every input.
20fuzz_target!(|data: &[u8]| {
21 if let Ok(track) = webvtt::parse(data) {
22 check(&track);
23 }
24 let text = String::from_utf8_lossy(data);
25 if let Ok(track) = webvtt::parse(text.as_bytes()) {
26 check(&track);
27 }
28 let mut headed = b"WEBVTT\n\n".to_vec();
29 headed.extend_from_slice(data);
30 if let Ok(track) = webvtt::parse(&headed) {
31 check(&track);
32 }
33});