Skip to content

Expand benchmarks and add cargo-fuzz targets#5

Merged
sunsided merged 5 commits into
mainfrom
feature/benches-and-fuzz
May 31, 2026
Merged

Expand benchmarks and add cargo-fuzz targets#5
sunsided merged 5 commits into
mainfrom
feature/benches-and-fuzz

Conversation

@sunsided

Copy link
Copy Markdown
Owner

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

  • Benchmarks (benches/lib.rs): add groups for window generation (Hann, Blackman-Harris, Kaiser, Gaussian), spectrum helpers (magnitude, power_to_db), and - behind the mel feature - a log-mel + MFCC pipeline, alongside the existing forward/streaming/round-trip benches.
  • Fuzzing (fuzz/): a cargo-fuzz crate 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 beta cannot loop forever).
  • Taskfile: fuzz:list, fuzz:build, fuzz:run and a CI-friendly fuzz:smoke (short run of every target); MSRV var bumped to 1.85 to match Cargo.toml.

Notes

  • The fuzz crate is its own workspace (empty [workspace] table) so it stays out of the library's build graph; corpora/artifacts are gitignored.
  • Fuzzing requires nightly + cargo-fuzz. Local smoke runs (~12s each) found no crashes: window 166k execs, round-trip 457k, config 36k.

How to review

fuzz/fuzz_targets/*.rs are 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.rs is mechanical. The Taskfile gains a fuzz:* group; fuzz:smoke is the one suitable for CI.

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`.
Copilot AI review requested due to automatic review settings May 31, 2026 19:26
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Taskfile.dist.yaml
Comment thread fuzz/fuzz_targets/stft_roundtrip.rs
Comment thread fuzz/fuzz_targets/stft_config.rs Outdated
Comment thread fuzz/fuzz_targets/stft_config.rs
Comment thread benches/lib.rs
Comment thread benches/lib.rs
sunsided added 3 commits May 31, 2026 21:30
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.
@sunsided sunsided merged commit f5858bb into main May 31, 2026
10 checks passed
@sunsided sunsided deleted the feature/benches-and-fuzz branch May 31, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants