Expand benchmarks and add cargo-fuzz targets#5
Merged
Conversation
Benchmarks: add window-generation (Hann/Blackman-Harris/Kaiser/ Gaussian), spectrum helpers (magnitude, power_to_db) and, behind the `mel` feature, a log-mel + MFCC group, alongside the existing forward/streaming/round-trip benches. Fuzzing: add a libFuzzer `fuzz/` crate with three targets: - stft_roundtrip: forward then inverse STFT on arbitrary bytes; - stft_config: arbitrary bounded window/hop/fft-size + streaming run; - window: every window family at arbitrary length/parameters. All assert the absence of panics/hangs. Smoke-runs found no crashes. Taskfile: add fuzz:list/build/run/smoke tasks and bump the MSRV var to 1.85 to match Cargo `rust-version`.
Builds the cargo-fuzz targets and runs each for 60s on every push to main and pull request, catching panics/hangs in regression. Uses the nightly toolchain (required by libFuzzer) and clears the global `-D warnings` so it does not clash with the sanitizer flags cargo-fuzz injects.
There was a problem hiding this comment.
Pull request overview
This PR expands the crate’s performance benchmarking surface area and adds a cargo-fuzz suite to exercise STFT/window/reconstruction paths under adversarial inputs, without modifying library code.
Changes:
- Extended Criterion benchmarks to cover window generation, spectrum helpers, and (behind
mel) a log-mel + MFCC pipeline. - Added a standalone
fuzz/crate with three libFuzzer targets (stft_roundtrip,stft_config,window). - Added Taskfile targets to list/build/run fuzzers and a CI-friendly smoke run; updated MSRV var to match
Cargo.toml.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Taskfile.dist.yaml | Adds fuzz:* tasks and updates MSRV variable. |
| benches/lib.rs | Adds benchmarks for window generation, spectrum helpers, and optional mel/MFCC pipeline. |
| fuzz/Cargo.toml | Introduces a standalone cargo-fuzz crate with three fuzz targets. |
| fuzz/.gitignore | Ignores fuzz artifacts, corpora, and lockfile. |
| fuzz/fuzz_targets/window.rs | Fuzz target for generating window families across parameters. |
| fuzz/fuzz_targets/stft_roundtrip.rs | Fuzz target for forward+inverse STFT round-trip on arbitrary bytes-as-samples. |
| fuzz/fuzz_targets/stft_config.rs | Fuzz target for bounded STFT configurations plus a streaming run. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The @cargo-fuzz shorthand ref did not actually install the binary (the step passed but `cargo fuzz` was missing). Use the documented taiki-e/install-action@v2 with `tool: cargo-fuzz`.
cargo-fuzz defaulted to x86_64-unknown-linux-musl (the prebuilt binary is musl-static), which is not installed and whose statically linked libc is incompatible with the address sanitizer. Pin x86_64-unknown-linux-gnu on build and run.
- fuzz/stft_roundtrip, fuzz/stft_config: cap decoded/consumed samples at 65536 so large libFuzzer corpora cannot cause OOM/timeouts that masquerade as findings. - fuzz/stft_config: fix the hop range to 1..=win ((h % win) + 1) so the non-overlapping (hop == win) case is actually exercised. - benches: reset the power buffer each iteration via iter_batched_ref, since power_to_db mutates in place (previously measured garbage after the first iteration). - benches: generate the mel benchmark signal at its own 16 kHz fs so the filterbank bins line up with the spectrogram bins. - Taskfile: fix the fuzz:run example to include the `--` separator before libFuzzer flags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Broadens benchmark coverage and adds a libFuzzer-based fuzzing suite so the transform, window and reconstruction code is exercised against adversarial input. No library code changes - this is tests/benches/tooling only.
Key changes
benches/lib.rs): add groups for window generation (Hann, Blackman-Harris, Kaiser, Gaussian), spectrum helpers (magnitude,power_to_db), and - behind themelfeature - a log-mel + MFCC pipeline, alongside the existing forward/streaming/round-trip benches.fuzz/): acargo-fuzzcrate with three targets:stft_roundtrip- forward then inverse STFT over arbitrary bytes read as f32 samples;stft_config- arbitrary but bounded window/hop/fft-size plus a streaming run;window- every window family at arbitrary length and parameters.Each asserts the absence of panics and hangs (the Kaiser Bessel series is iteration-capped, so pathological
betacannot loop forever).fuzz:list,fuzz:build,fuzz:runand a CI-friendlyfuzz:smoke(short run of every target); MSRV var bumped to 1.85 to matchCargo.toml.Notes
[workspace]table) so it stays out of the library's build graph; corpora/artifacts are gitignored.cargo-fuzz. Local smoke runs (~12s each) found no crashes: window 166k execs, round-trip 457k, config 36k.How to review
fuzz/fuzz_targets/*.rsare the load-bearing additions - check that each target bounds its inputs (lengths, fft size) to avoid false-positive OOM/timeouts while still covering the real configuration space.benches/lib.rsis mechanical. The Taskfile gains afuzz:*group;fuzz:smokeis the one suitable for CI.