edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
fuzzsubs: cargo-fuzz targets for ec-subs, ec-ass, ec-pgs
Goal: DONE.md shared gate 2 for ec-subs (SRT, WebVTT, markup, IR conversion), ec-ass (script,
section, event and override-tag parsing) and ec-pgs (segment parsing, RLE decode, composition to
bitmaps). One standalone cargo-fuzz crate per crate, same layout as crates/ec-ogg/fuzz/.
Base sha: a19477ea (main at worktree creation).
What changed
crates/ec-subs/fuzz/:ec-subs-fuzz, targetssrt,webvtt,markup,ir. Text targets run the input bytes and then the lossy-UTF-8 text.webvttalso tries aWEBVTTheader in front.markupwraps the input in a one-cue SRT and WebVTT document so the shared tag stack is reached.crates/ec-ass/fuzz/:ec-ass-fuzz, targetsscript(whole document, bytes and lossy text),styles(first byte picks V4 or V4+ table, and whether a Format line is present),events(input as one Dialogue row),overrides(first byte picks WrapStyle 0 to 3; input is the Text field).crates/ec-pgs/fuzz/:ec-pgs-fuzz, targetssegments(raw.supbytes split in two at a point the first byte chooses),rle(structured ODS whose declared size comes from input),compose(input read as (kind, length, body) records framed as valid segments).seed.shin each crate: ec-subs seeds fromfixtures/subs/real.srtplus a generated WebVTT twin; ec-ass fromreal.ass(whole file, and its Dialogue and Style rows); ec-pgs frompgs-1080p.sup..gitignorecovers target, corpus, artifacts, coverage.- Library fixes (all found by reading the code; none by fuzzing, see below):
ec-subs/src/markup.rsparse_clock: the hours/minutes/seconds sums and the microsecond scaling arechecked_*. A clock that does not fit an i64 of microseconds now returnsNone(the cue is skipped and counted) instead of panicking in debug.- Markup nesting capped at 64 open frames (
MAX_NEST). Before, a cue of a million<i>built a tree that was quadratic to close (rpositionover the stack per close tag) and too deep forplain_textandDrop. - Entity lookup for
&scans at most 11 bytes for;. Before, each bare&scanned to the end of the cue, so a run of&was quadratic. utf16decoding usesas_chunks::<2>(clippy; same result).
ec-ass/src/lib.rsalignment:(code - 1)becamecode.wrapping_sub(1) % 3 + 1.i32::MIN(a number a style row or\ancan state) panicked. Results are identical for every other input.WrapStyleis read once from the header, not searched for on every Dialogue row (that search was quadratic on long headers). The firstWrapStyle:line still wins, as before.
ec-pgs/src/lib.rs- Object dimensions above
MAX_DIMENSION(4096) are refused withError::corrupt. Before, an object declared 65535x65535 allocated its RLE bitmap at 4 GB. The oversized partial is dropped, later fragments under that id cannot attach to an older object, and the rest of the buffer is still consumed.pushreturns the first such error after the buffer is through, so a caller sees the refusal; this is a change topush's error contract, documented in its doc comment. - Canvas above 4096 in either dimension is refused the same way (was a 17 GB RGBA
vec!). take_frameusesVecDeque::pop_front(wasVec::remove(0), quadratic on a drained backlog).
- Object dimensions above
- Tests (all in each crate's
tests/, inputs inlined, no fixtures needed):crates/ec-subs/tests/fuzz_regressions.rs: overflowing clock, cue with overflowing clock skipped, 200k nested<i>/<b>(text survives), 100k bare&(linear and unchanged).crates/ec-ass/tests/fuzz_regressions.rs:-2147483648alignment in a style row and in\an, Dialogue clock overflow skipped, first WrapStyle governs\n, 20k-line header with 5k rows.crates/ec-pgs/tests/fuzz_regressions.rs: 65535x65535 object refused and the next legal set still renders, 65535x65535 canvas refused.
crates/ec-subs/tests/real_library.rs: twochunks_exact(4)calls changed toas_chunks::<4>().0.iter()so--all-targetsclippy is clean. Assertions untouched.
Bugs found and fixed
Fuzzing found no crash, timeout or OOM in 120 s per target (see table). The fixes above come from reading the parsers. Each one is an input the parser must handle that either panicked in debug (overflow), allocated without a bound, or took quadratic time. The regression tests above cover each.
Not verified: I did not re-run the new regression tests against the pre-fix code to confirm they fail there. The overflow and allocation cases are reasoned from the code; the tests pass on the fix.
Verify commands and results (all via scripts/remote-run.sh fuzzsubs, host a or b)
cargo +nightly fuzz build --fuzz-dir crates/<c>/fuzzfor ec-subs, ec-ass, ec-pgs: exit 0, all 11 targets built.- Fuzz, each target
cargo +nightly fuzz run --fuzz-dir crates/<c>/fuzz <t> -- -max_total_time=120 -rss_limit_mb=2048 -timeout=10:
| target | exit | executions | crash/timeout/OOM |
|---|---|---|---|
| ec-subs srt | 0 | 4,818 | none |
| ec-subs webvtt | 0 | 3,801 | none |
| ec-subs markup | 0 | 3,704 | none |
| ec-subs ir | 0 | 3,523 | none |
| ec-ass script | 0 | 10,345 | none |
| ec-ass styles | 0 | 955,789 | none |
| ec-ass events | 0 | 1,790,123 | none |
| ec-ass overrides | 0 | 1,449,491 | none |
| ec-pgs segments | 0 | 22,570 | none |
| ec-pgs rle | 0 | 17,524 | none |
| ec-pgs compose | 0 | 21,231 | none |
Fuzz runs used the code before the clippy-only edits (as_chunks in ec-pgs pds, ec-subs utf16,
and the real_library test); those edits do not change behaviour and the release tests pass after them.
cargo clippy -p ec-subs -p ec-ass -p ec-pgs --all-targets -- -D warnings: exit 0, clean.cargo test --no-fail-fast -p ec-subs -p ec-ass -p ec-pgs(debug): all suites pass; the real PGS fixture test takes about 30 s in debug.cargo test --no-fail-fast --release -p ec-subs -p ec-ass -p ec-pgs: exit 0. Counts: ec-ass 4 unit- 4 integration; ec-pgs 5 unit + 3 integration; ec-subs 13 unit + 4 regression + 2 real-library.
The real-library PGS test needed
EC_REQUIRE_FIXTURES=1and the fixture symlink.
- 4 integration; ec-pgs 5 unit + 3 integration; ec-subs 13 unit + 4 regression + 2 real-library.
The real-library PGS test needed
Design decisions to review
- PGS frame queue stays unbounded. A cap that drops the oldest frame broke the existing
a_real_pgs_stream_decodes_to_plausible_bitmapstest (it pushes the whole file, then drains), so it was reverted. A caller that never callstake_frameholds every frame. The fuzz targets drain after every push. - PGS object cap is 4096 in each dimension. The brief suggested this or the declared data length; the dimension cap is what is implemented. Declared data length is not separately checked.
Left open
- The gate asks for 1 CPU-hour per target. Only 120 s smoke runs were done, so the gate is not met.
- Corpora are seeded from fixtures only. No minimized corpus or coverage was measured. Seed corpora are not committed (git-ignored); the server-side corpus and artifact directories did not sync back.
- The
ec-substargets run at 30-40 exec/s (full parse per input, two passes for text). Expected for this input shape, not a finding. - The PGS RLE amplification (
renderdecodes each placed object once per END segment) is not cached. Linear in segments, not a quadratic path; left as is. fuzz/Cargo.lockfiles generated on the server are not in this commit.