edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # fuzzmp4: cargo-fuzz targets for ec-mp4 |
| 2 | |
| 3 | Goal: DONE.md shared gate 2, at least one cargo-fuzz target per untrusted entry point in |
| 4 | ec-mp4 (container open and sample tables, fragments, sample reads, esds/codec config, sniffer). |
| 5 | Base sha: 78ec1905 (main at worktree creation). |
| 6 | |
| 7 | ## What changed |
| 8 | - `crates/ec-mp4/fuzz/`: standalone cargo-fuzz crate (`ec-mp4-fuzz`, own `[workspace]`, path deps on |
| 9 | ec-mp4 and ec-core; ec-core is needed for the `Demuxer` trait). `.gitignore` for |
| 10 | `target`, `corpus`, `artifacts`, `coverage`. The root `Cargo.toml` already excludes `crates/*/fuzz`. |
| 11 | - `demux_mp4`: whole input as a file through `Mp4Demuxer::new`; lists tracks, duration, fragment |
| 12 | count; `next_packet` until error; then `read_sample` for every index of every stream. |
| 13 | - `esds_parse`: whole input as an `esds` payload through `Esds::parse`. |
| 14 | - `is_mp4`: `is_mp4` sniffer on the whole input. |
| 15 | - `seed.sh`: every mp4/m4a/mov/m4v fixture under `fixtures/audio` and `fixtures/video`. Files over 1 MiB |
| 16 | are re-cut with `ffmpeg -t {0.2,0.05,0.01} -c copy` until they fit. `esds_parse` gets the payload of |
| 17 | each seed's first `esds` box. `is_mp4` gets the first 64 bytes. Result: 41 demux_mp4, 12 esds_parse, |
| 18 | 41 is_mp4 seeds (13 MB corpus, git-ignored). |
| 19 | - `crates/ec-mp4/src/demux.rs`, two bugs found by the fuzzer, both fixed: |
| 20 | 1. **Fragment `trun` allocation (found at exec ~7.5k, fixed).** A `trun` with no per-sample fields |
| 21 | (width 0) took its sample count from its own header, unchecked, and pushed that many samples. |
| 22 | A 16-byte box claiming 0xFFFFFFF0 samples allocated the machine. Fix: a track's total sample count |
| 23 | (moov table plus all fragments) may not exceed the file length, the same ceiling `stsz` already |
| 24 | applies. Errors with `Error::corrupt`. |
| 25 | 2. **Channel count allocation (found at exec ~115k, fixed).** A QuickTime version-2 sound description |
| 26 | states its channel count as a 32-bit field, which went straight into `ChannelLayout::from_count`, |
| 27 | which allocates one channel position per channel. A 3.3 GB allocation from a 952-byte file. Fix: new |
| 28 | `channel_layout()` helper refuses counts over `MAX_CHANNELS = 64` with `Error::corrupt`. Used for |
| 29 | both the classic and version-2 paths. |
| 30 | - `crates/ec-mp4/tests/mp4.rs`: regression test `a_trun_claiming_more_samples_than_the_file_is_refused_not_allocated` |
| 31 | (appends a crafted `moof` to the mono AAC fixture; must be an `Err`). |
| 32 | - `crates/ec-mp4/src/demux.rs` unit test `a_sound_description_stating_billions_of_channels_is_refused` |
| 33 | (v2 entry with channel count 0xFFFFFFF0 is refused; 6 channels still builds a 5.1 layout). |
| 34 | - `crates/ec-mp4/tests/mp4.rs` line 249: `name_of(&path)` changed to `name_of(path)`. This was a |
| 35 | pre-existing `clippy::needless_borrow` error that blocked the `-D warnings` gate, not part of the fuzz work. |
| 36 | |
| 37 | ## Verify commands and results |
| 38 | All through `scripts/remote-run.sh fuzzmp4`, from the worktree. Host a unless noted; host b and local were busy or |
| 39 | not used. |
| 40 | - `cargo +nightly fuzz build --fuzz-dir crates/ec-mp4/fuzz`: exit 0 (3 targets). |
| 41 | - `cargo +nightly fuzz run is_mp4 --fuzz-dir crates/ec-mp4/fuzz -- -max_total_time=120 -rss_limit_mb=3000 -timeout=10`: |
| 42 | exit 0, 102,436,456 runs in 121 s, no crash. Run before the fixes; `is_mp4` does not reach the changed code. |
| 43 | - `... esds_parse ...`: exit 0, 18,809,040 runs in 121 s, no crash. Run before the fixes; `esds.rs` is unchanged. |
| 44 | - `... demux_mp4 ...` before fixes: OOM at exec 7,476 (trun allocation). |
| 45 | - `... demux_mp4 ...` after fix 1: OOM at exec 114,981 (channel count allocation). |
| 46 | - `... demux_mp4 ...` after both fixes: exit 0, 4,630,555 runs in 121 s, no crash, no OOM, no timeout. |
| 47 | - Reproducer replay after fix 2: `cargo +nightly fuzz run demux_mp4 ... <oom input>`: exit 0, input now handled. |
| 48 | - `cargo test -p ec-mp4 --release` (server, host a): exit 0. Lib 19 passed; mp4 integration 16 passed, 1 ignored |
| 49 | (pre-existing); rotation 3 passed. Includes both new regression tests. |
| 50 | - `cargo clippy -p ec-mp4 --all-targets -- -D warnings` (server, host a): exit 0. |
| 51 | - `cargo fmt --check`: not run; rustfmt is not installed for the server toolchain. |
| 52 | |
| 53 | Crashes found: 2 distinct (trun allocation; channel count allocation). Both fixed on the first attempt, both |
| 54 | have a regression test. Timeouts: none. Crash inputs are not committed; the regression tests carry the case. |
| 55 | |
| 56 | ## Left open |
| 57 | - The gate asks for 1 CPU-hour per target. Only 120 s smoke runs were done, so the gate is not met. |
| 58 | - `esds_parse` and `is_mp4` were smoke-run before the two demux fixes. Their code paths are unchanged, but a |
| 59 | post-fix re-run has not been done. |
| 60 | - Only the first 4 KB of each `ec-mp4` sample entry is exercised per iteration; no per-codec entry seeds beyond |
| 61 | the fixtures. Coverage was not measured. |
| 62 | - No minimised corpus; `fuzz/Cargo.lock` was generated on the host and is not in this commit. |
| 63 | - No `mux` target: the muxer writes only caller-supplied data, so it is not an untrusted entry point. |