forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

fuzzsubs.report.md106 lines, 7.7 KiBHistoryRawDownload
1# fuzzsubs: cargo-fuzz targets for ec-subs, ec-ass, ec-pgs
2
3Goal: DONE.md shared gate 2 for ec-subs (SRT, WebVTT, markup, IR conversion), ec-ass (script,
4section, event and override-tag parsing) and ec-pgs (segment parsing, RLE decode, composition to
5bitmaps). One standalone cargo-fuzz crate per crate, same layout as `crates/ec-ogg/fuzz/`.
6Base sha: a19477ea (main at worktree creation).
7
8## What changed
9- `crates/ec-subs/fuzz/`: `ec-subs-fuzz`, targets `srt`, `webvtt`, `markup`, `ir`. Text targets run
10 the input bytes and then the lossy-UTF-8 text. `webvtt` also tries a `WEBVTT` header in front.
11 `markup` wraps the input in a one-cue SRT and WebVTT document so the shared tag stack is reached.
12- `crates/ec-ass/fuzz/`: `ec-ass-fuzz`, targets `script` (whole document, bytes and lossy text),
13 `styles` (first byte picks V4 or V4+ table, and whether a Format line is present), `events`
14 (input as one Dialogue row), `overrides` (first byte picks WrapStyle 0 to 3; input is the Text field).
15- `crates/ec-pgs/fuzz/`: `ec-pgs-fuzz`, targets `segments` (raw `.sup` bytes split in two at a
16 point the first byte chooses), `rle` (structured ODS whose declared size comes from input),
17 `compose` (input read as (kind, length, body) records framed as valid segments).
18- `seed.sh` in each crate: ec-subs seeds from `fixtures/subs/real.srt` plus a generated WebVTT twin;
19 ec-ass from `real.ass` (whole file, and its Dialogue and Style rows); ec-pgs from `pgs-1080p.sup`.
20 `.gitignore` covers target, corpus, artifacts, coverage.
21- Library fixes (all found by reading the code; none by fuzzing, see below):
22 - `ec-subs/src/markup.rs`
23 - `parse_clock`: the hours/minutes/seconds sums and the microsecond scaling are `checked_*`. A
24 clock that does not fit an i64 of microseconds now returns `None` (the cue is skipped and
25 counted) instead of panicking in debug.
26 - Markup nesting capped at 64 open frames (`MAX_NEST`). Before, a cue of a million `<i>` built a
27 tree that was quadratic to close (`rposition` over the stack per close tag) and too deep for
28 `plain_text` and `Drop`.
29 - Entity lookup for `&` scans at most 11 bytes for `;`. Before, each bare `&` scanned to the
30 end of the cue, so a run of `&` was quadratic.
31 - `utf16` decoding uses `as_chunks::<2>` (clippy; same result).
32 - `ec-ass/src/lib.rs`
33 - `alignment`: `(code - 1)` became `code.wrapping_sub(1) % 3 + 1`. `i32::MIN` (a number a style
34 row or `\an` can state) panicked. Results are identical for every other input.
35 - `WrapStyle` is read once from the header, not searched for on every Dialogue row (that search
36 was quadratic on long headers). The first `WrapStyle:` line still wins, as before.
37 - `ec-pgs/src/lib.rs`
38 - Object dimensions above `MAX_DIMENSION` (4096) are refused with `Error::corrupt`. Before, an
39 object declared 65535x65535 allocated its RLE bitmap at 4 GB. The oversized partial is dropped,
40 later fragments under that id cannot attach to an older object, and the rest of the buffer is
41 still consumed. `push` returns the first such error after the buffer is through, so a caller
42 sees the refusal; this is a change to `push`'s error contract, documented in its doc comment.
43 - Canvas above 4096 in either dimension is refused the same way (was a 17 GB RGBA `vec!`).
44 - `take_frame` uses `VecDeque::pop_front` (was `Vec::remove(0)`, quadratic on a drained backlog).
45- Tests (all in each crate's `tests/`, inputs inlined, no fixtures needed):
46 - `crates/ec-subs/tests/fuzz_regressions.rs`: overflowing clock, cue with overflowing clock skipped,
47 200k nested `<i>`/`<b>` (text survives), 100k bare `&` (linear and unchanged).
48 - `crates/ec-ass/tests/fuzz_regressions.rs`: `-2147483648` alignment in a style row and in `\an`,
49 Dialogue clock overflow skipped, first WrapStyle governs `\n`, 20k-line header with 5k rows.
50 - `crates/ec-pgs/tests/fuzz_regressions.rs`: 65535x65535 object refused and the next legal set
51 still renders, 65535x65535 canvas refused.
52- `crates/ec-subs/tests/real_library.rs`: two `chunks_exact(4)` calls changed to
53 `as_chunks::<4>().0.iter()` so `--all-targets` clippy is clean. Assertions untouched.
54
55## Bugs found and fixed
56Fuzzing found no crash, timeout or OOM in 120 s per target (see table). The fixes above come from
57reading the parsers. Each one is an input the parser must handle that either panicked in debug
58(overflow), allocated without a bound, or took quadratic time. The regression tests above cover each.
59
60Not verified: I did not re-run the new regression tests against the pre-fix code to confirm they
61fail there. The overflow and allocation cases are reasoned from the code; the tests pass on the fix.
62
63## Verify commands and results (all via `scripts/remote-run.sh fuzzsubs`, host a or b)
64- `cargo +nightly fuzz build --fuzz-dir crates/<c>/fuzz` for ec-subs, ec-ass, ec-pgs: exit 0, all 11 targets built.
65- Fuzz, each target `cargo +nightly fuzz run --fuzz-dir crates/<c>/fuzz <t> -- -max_total_time=120 -rss_limit_mb=2048 -timeout=10`:
66
67| target | exit | executions | crash/timeout/OOM |
68|----------------------|------|-----------:|-------------------|
69| ec-subs srt | 0 | 4,818 | none |
70| ec-subs webvtt | 0 | 3,801 | none |
71| ec-subs markup | 0 | 3,704 | none |
72| ec-subs ir | 0 | 3,523 | none |
73| ec-ass script | 0 | 10,345 | none |
74| ec-ass styles | 0 | 955,789 | none |
75| ec-ass events | 0 | 1,790,123 | none |
76| ec-ass overrides | 0 | 1,449,491 | none |
77| ec-pgs segments | 0 | 22,570 | none |
78| ec-pgs rle | 0 | 17,524 | none |
79| ec-pgs compose | 0 | 21,231 | none |
80
81 Fuzz runs used the code before the clippy-only edits (`as_chunks` in ec-pgs `pds`, ec-subs `utf16`,
82 and the real_library test); those edits do not change behaviour and the release tests pass after them.
83- `cargo clippy -p ec-subs -p ec-ass -p ec-pgs --all-targets -- -D warnings`: exit 0, clean.
84- `cargo test --no-fail-fast -p ec-subs -p ec-ass -p ec-pgs` (debug): all suites pass; the real PGS
85 fixture test takes about 30 s in debug.
86- `cargo test --no-fail-fast --release -p ec-subs -p ec-ass -p ec-pgs`: exit 0. Counts: ec-ass 4 unit
87 + 4 integration; ec-pgs 5 unit + 3 integration; ec-subs 13 unit + 4 regression + 2 real-library.
88 The real-library PGS test needed `EC_REQUIRE_FIXTURES=1` and the fixture symlink.
89
90## Design decisions to review
91- PGS frame queue stays unbounded. A cap that drops the oldest frame broke the existing
92 `a_real_pgs_stream_decodes_to_plausible_bitmaps` test (it pushes the whole file, then drains), so
93 it was reverted. A caller that never calls `take_frame` holds every frame. The fuzz targets drain
94 after every push.
95- PGS object cap is 4096 in each dimension. The brief suggested this or the declared data length;
96 the dimension cap is what is implemented. Declared data length is not separately checked.
97
98## Left open
99- The gate asks for 1 CPU-hour per target. Only 120 s smoke runs were done, so the gate is not met.
100- Corpora are seeded from fixtures only. No minimized corpus or coverage was measured. Seed corpora
101 are not committed (git-ignored); the server-side corpus and artifact directories did not sync back.
102- The `ec-subs` targets run at 30-40 exec/s (full parse per input, two passes for text). Expected for
103 this input shape, not a finding.
104- The PGS RLE amplification (`render` decodes each placed object once per END segment) is not cached.
105 Linear in segments, not a quadratic path; left as is.
106- `fuzz/Cargo.lock` files generated on the server are not in this commit.