Skip to content

test: fuzz the header readers, briefly on every pull request and for ten minutes a week - #9

Merged
stephen-masters merged 3 commits into
mainfrom
feat/fuzz-headers
Nov 1, 2026
Merged

stephen-masters merged 3 commits into
mainfrom
feat/fuzz-headers

Conversation

@stephen-masters

Copy link
Copy Markdown
Contributor

Summary

  • scripts/fuzz_headers.py: takes the hostile corpus's well-formed files (and, when Pillow is present, files Pillow writes) as seeds, damages them at random and runs each result through the same readers the check uses. Mutations: bit flips, boundary values written into 2- and 4-byte fields in either endian, truncation, inserted and deleted runs, duplicated blocks, splices from another seed. Every outcome must be a header or a HeaderError within five seconds. Anything else is a finding: the input and its traceback go to fuzz-findings/ (git-ignored) and the run exits 1.
  • CI: thirty seconds on one Python in the test job; weekly: ten minutes in security.yml, with any findings kept as an artefact. Both are seeded by the run id, passed through the environment, so a failure can be repeated by hand with --seed.
  • tests/test_fuzz.py keeps the fuzzer itself honest: a short run finds nothing, a reader that raises the wrong thing is recorded as a finding, and main parses a seed.
  • CONTRIBUTING.md lists the command among the checks; AGENTS.md's hostile-corpus rule says where findings go.

Stage 3 of brief 022 (the fuzzing job).

Test plan

  • Locally, seeds 1 to 4 for sixty seconds each: about 4.6 million inputs a minute across JPEG, PNG and TIFF, no findings
  • ruff, ruff format, mypy strict (the script is type-checked), 379 tests, coverage 99 percent
  • zizmor on the workflows: no findings
  • CI's own thirty-second run on this pull request

🤖 Generated with Claude Code

stephen-masters and others added 3 commits November 1, 2026 22:05
…ten minutes a week

scripts/fuzz_headers.py takes the hostile corpus's well-formed files as
seeds, damages them at random (bit flips, boundary values in length and
offset fields, truncation, inserted and deleted runs, duplicated blocks,
splices from another seed) and runs the result through the same readers
the check uses. Every outcome must be a header or a HeaderError within
five seconds; anything else is written to fuzz-findings/ with its
traceback, for turning into a test, and the run fails.

CI runs it for thirty seconds on one Python; the weekly security run for
ten minutes, keeping any findings as an artefact. Both seed it with the
run id so a failure can be repeated by hand. Four minutes across four
seeds locally, about four and a half million inputs a minute, found
nothing. Stage 3 of brief 022.

Co-authored-by: Yvette Mankerian <yvettekm@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@stephen-masters
stephen-masters merged commit 3b232df into main Nov 1, 2026
11 checks passed
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