Skip to content

Add fuzzing for the signed-file parsers - #69

Open
jqnatividad wants to merge 4 commits into
Kijewski:mainfrom
jqnatividad:fuzzing
Open

jqnatividad wants to merge 4 commits into
Kijewski:mainfrom
jqnatividad:fuzzing

Conversation

@jqnatividad

@jqnatividad jqnatividad commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds cargo-fuzz targets for the code that reads untrusted signed files, plus a short CI job that runs them.

Targets (fuzz/fuzz_targets/):

  • zip: verify_zip and copy_and_unsign_zip
  • tar: verify_tar and copy_and_unsign_tar, including the gzip-tail and base64 signature block
  • signatures: read_signatures, the signature block header

Seeds (fuzz/seeds/): small real signed and unsigned .zip/.tar.gz files. They're signed with the fixed key in fuzz_targets/common.rs, so the fuzzer starts from valid files and reaches the signature-matching code, not just the early rejections.

Isolation: fuzz/ has its own [workspace], so normal builds, cargo fmt --all, clippy --workspace and cargo sort --workspace are unaffected and don't need nightly or libFuzzer. Run instructions are a comment at the top of fuzz/Cargo.toml. corpus/ and artifacts/ are gitignored.

CI: a separate Fuzz workflow (.github/workflows/fuzz.yml), with one matrix job per target on nightly. Each runs for 60 seconds from the seeds, and crash inputs are uploaded as artifacts if a job fails.

Fuzzing is random, so any run can hit a bug that has been in the code all along. To keep that from turning unrelated PRs red, the workflow runs only when something that affects the parsers changes:

  • on PRs and pushes to main that touch api/**, fuzz/**, the workspace Cargo.toml (dependency bumps like zip or ed25519-dalek change parser behavior) or the workflow itself,
  • weekly, and
  • on demand (workflow_dispatch).

ci.yml is unchanged. If you'd prefer it to run only on the schedule, drop the push/pull_request triggers. I'd also suggest not making it a required check.

Results

10 minutes per target locally, no crashes, panics, OOMs or timeouts:

Target Runs Coverage
signatures ~288M 71
tar ~9.2M 1,180
zip ~3.9M 2,454

Coverage had levelled off. That matches the code: parser allocations are capped at BUF_LIMIT (64 KiB) before allocating, and offset math uses checked arithmetic.

Testing

  • All three targets build and run on nightly, and a run from a fresh checkout (no corpus/) works with the job's mkdir -p.
  • cargo +nightly fmt --check, cargo +nightly clippy and typos are clean for fuzz/. actionlint is clean for both workflows.
  • The root workspace still contains only zipsign-api and zipsign.

🤖 Generated with Claude Code

jqnatividad and others added 4 commits October 25, 2026 10:12
Three libFuzzer targets for the code that reads untrusted signed files:

* `zip`: verify_zip and copy_and_unsign_zip
* `tar`: verify_tar and copy_and_unsign_tar
* `signatures`: read_signatures (the signature block header)

Seeds in fuzz/seeds/ are real signed and unsigned files, signed with
the fixed key in fuzz_targets/common.rs, so the fuzzer starts from
valid structure and reaches the signature-matching code. The crate has
its own [workspace] and stays out of normal builds and CI.

10 minutes per target (~300M signatures / 9M tar / 4M zip runs) found
no crashes, panics, OOMs or timeouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One matrix job per target on nightly, starting from the committed seeds.
Crash inputs are uploaded as artifacts when a job fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fuzzing is random, so a 60-second run can hit a pre-existing bug and
turn an unrelated PR red. Run it from a separate workflow only when
api/, fuzz/, the workspace Cargo.toml (dependency bumps change parser
behavior) or the workflow itself change, plus weekly and on demand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The prebuilt cargo-fuzz from taiki-e/install-action is a musl binary
and defaults to x86_64-unknown-linux-musl, which has no
AddressSanitizer support ("sanitizer is incompatible with statically
linked libc"). Pass the host triple from `rustc -vV` explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant