forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

srt.rs28 lines, 873 bytesHistoryRawDownload
1#![no_main]
2
3use ec_subs::{SubtitleTrack, plain_text, srt};
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// SubRip, once with the bytes as they are (invalid UTF-8 and UTF-16 BOMs included) and once with
19// the lossy-UTF-8 text a caller holding a `String` would hand over.
20fuzz_target!(|data: &[u8]| {
21 if let Ok(track) = srt::parse(data) {
22 check(&track);
23 }
24 let text = String::from_utf8_lossy(data);
25 if let Ok(track) = srt::parse(text.as_bytes()) {
26 check(&track);
27 }
28});