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 | # fuzzflac: cargo-fuzz targets for ec-flac |
| 2 | |
| 3 | Goal: DONE.md shared gate 2, at least one cargo-fuzz target per untrusted entry point in |
| 4 | ec-flac (whole-file decode, per-frame decode, metadata parse, and an encode/decode roundtrip). |
| 5 | Base sha: 78ec1905 (main at worktree creation). |
| 6 | |
| 7 | ## What changed |
| 8 | - `crates/ec-flac/fuzz/`: standalone cargo-fuzz crate (`ec-flac-fuzz`, own `[workspace]`, path dep on ec-flac). |
| 9 | - `decode_file`: whole input as a .flac buffer through `FlacReader::new` then `decode_all`. |
| 10 | - `decode_frame`: byte 0 selects one of five fixed STREAMINFOs (as a container carries them); the rest |
| 11 | is bare frames fed to `FlacReader::frames` and `next_block` until it stops. Asserts the decoded |
| 12 | channel count and block length match the frame header. |
| 13 | - `parse_metadata`: `StreamInfo::parse` on the whole input (asserts `to_bytes` reproduces the first 34 |
| 14 | bytes), then `FlacReader::new`, `seek_table`, and `seek_to_sample` at 0 and `u64::MAX`. |
| 15 | - `encode_roundtrip`: header bytes pick channels (1..=8), bit depth (4..=32), rate, and block size; the rest |
| 16 | is i32 samples clamped to the bit depth. `encode` then `decode_all` must return the input exactly. |
| 17 | - `seed.sh`: every root `fixtures/audio/flac-*.flac` plus the xiph testbench (subset, uncommon, faulty) as |
| 18 | decode_file and parse_metadata seeds (92 each); the same files with metadata stripped behind selector 0 as |
| 19 | decode_frame seeds (90). `encode_roundtrip` has no seeds. |
| 20 | - `.gitignore`: target, corpus, artifacts, coverage. |
| 21 | - `crates/ec-flac/src/decode.rs`: fix for the crash found by `parse_metadata` (see below). Regression test |
| 22 | `seek_table_offset_overflow_does_not_panic` in the existing `tests` module. |
| 23 | - `crates/ec-flac/src/checksum.rs`, `src/lib.rs` (test), `tests/encode_matrix.rs`: `chunks_exact` replaced by |
| 24 | `as_chunks` (same bytes, same remainder handling). Needed because the current clippy (rust 1.99) flags |
| 25 | `chunks_exact` with a constant size; `-D warnings` failed on these before any change of mine. |
| 26 | |
| 27 | ## Crash found and fixed |
| 28 | - `parse_metadata`, libFuzzer: `attempt to add with overflow` at `decode.rs:335`, in `seek_to_sample`. |
| 29 | A SEEKTABLE point with offset `u64::MAX` made `first_frame + p.offset as usize` overflow. Debug builds |
| 30 | panic; release builds would wrap and move the read position to an arbitrary offset. |
| 31 | - Fix: the offset is converted with `usize::try_from` and added with `checked_add`; an out-of-range point is |
| 32 | treated as "no such point" (seek to the first frame, answer 0), the same as the existing fallback. |
| 33 | - Regression test: `decode::tests::seek_table_offset_overflow_does_not_panic`. It was not run against the |
| 34 | pre-fix code, so the test's failure before the fix is not observed. |
| 35 | - Fix attempts used: 1 (it passed the replay and the re-run on the first try). |
| 36 | |
| 37 | ## Verify commands and results |
| 38 | Run locally (see "Where it ran"): `CARGO_TARGET_DIR=~/.cache/tgt-fuzzflac TMPDIR=~/.cache/tmp-fuzzflac`, `CARGO_BUILD_JOBS=4`. |
| 39 | - `cargo +nightly fuzz build --fuzz-dir crates/ec-flac/fuzz`: exit 0 (all four targets built). |
| 40 | - `cargo +nightly fuzz run decode_file --fuzz-dir crates/ec-flac/fuzz -- -max_total_time=120 -rss_limit_mb=3000 -timeout=10`: |
| 41 | exit 0, 4485 runs in 121 s, no crash. |
| 42 | - `... decode_frame ...`: exit 0, 3954 runs in 121 s, no crash. |
| 43 | - `... parse_metadata ...` (first run): exit 1, crash at seek_to_sample overflow (above). 251238 runs in the |
| 44 | re-run after the fix: exit 0, no crash. |
| 45 | - `... encode_roundtrip ...`: exit 0, 652390 runs in 121 s, no roundtrip mismatch and no assert failure. |
| 46 | - Replay of the crash input against the fixed target: exit 0. |
| 47 | - `cargo clippy -p ec-flac --all-targets -- -D warnings`: exit 0 (after the chunks_exact to as_chunks change). |
| 48 | - `cargo test -p ec-flac --release -j4`: exit 0. Unit 16 passed (includes the regression test); |
| 49 | integration `xiph_vectors` 2 passed; `encode_matrix` 4 passed; 0 failed. |
| 50 | |
| 51 | ## Where it ran |
| 52 | - The worker brief said to run through `scripts/remote-run.sh fuzzflac`. Host a was slot-busy for the whole |
| 53 | 10-minute window (exit 75) on two tries; host b was slot-busy too (exit 75, two windows). Per the |
| 54 | coordinator's message, everything ran locally from the worktree after that. No server result exists for this lane. |
| 55 | |
| 56 | ## Left open |
| 57 | - The gate asks for 1 CPU-hour per target. Only the 120 s smoke runs were done, so the gate is not met. |
| 58 | - `FlacDecoder` (the `ec_core::Decoder` container path, STREAMINFO from extradata) has no dedicated target; |
| 59 | `decode_frame` drives `FlacReader::frames` directly, which is the same frame decoder underneath. |
| 60 | - `encode_roundtrip` has no seeds; `decode_file` was not given the encoder's output as a seed. |
| 61 | - Corpus is seeded from fixtures only; no minimised corpus or coverage measured. |
| 62 | - `fuzz/Cargo.lock` was generated locally and is not in this commit (as in fuzzaudio1). |