Skip to content

Workflow python fuzz

github-actions[bot] edited this page Nov 2, 2026 · 4 revisions

python-fuzz

What it does. Runs every Atheris fuzz target a repository keeps under fuzz/ for a fixed time per target, fails the job on a crash and uploads the crashing input. Holds no token.

Why it exists. OpenSSF Scorecard's Fuzzing check credits a Python repository for exactly one thing: an import atheris in a *.py file in the tree (or OSS-Fuzz, ClusterFuzzLite, OneFuzz). Hypothesis does not count. This workflow makes that credit honest: the targets actually run, and a crash is a red job. The first rollout (v1.10.0, 2026-10-04) across five repositories found real defects (parsers that mishandled a bare carriage return, a null YAML key, wrong-shape JSON, an epoch that hung a C routine), each fixed with a failing test first.

What a target is

A file under fuzz-dir matching target-glob (default fuzz_*.py, searched recursively), run as python <target> -max_total_time=<seconds> -max_len=<max-len> -artifact_prefix=<dir>/ -print_final_stats=1. It must:

  • import atheris and wrap the imports of the code under test in atheris.instrument_imports(), or it fuzzes blind;
  • define def TestOneInput(data: bytes) -> None, drawing typed values from atheris.FuzzedDataProvider(data);
  • call atheris.Setup(sys.argv, TestOneInput) then atheris.Fuzz() under if __name__ == "__main__":;
  • raise only on a real bug. An error the code documents (a parser rejecting bad input) is caught inside the target.
import sys

import atheris

with atheris.instrument_imports():
    from my_pkg.parser import ParseError, parse


def TestOneInput(data: bytes) -> None:
    text = atheris.FuzzedDataProvider(data).ConsumeUnicodeNoSurrogates(1024)
    try:
        parse(text)
    except ParseError:
        pass  # documented rejection, not a bug


if __name__ == "__main__":
    atheris.Setup(sys.argv, TestOneInput)
    atheris.Fuzz()

Behaviour worth knowing

  • A missing fuzz/ directory, or one with no match, is a failure, not a skip. A caller that opts in without targets is wrong, and a silent pass would be the thing Scorecard was trying not to credit.
  • Every target runs even when an earlier one failed; the job fails if any did. A crash leaves crash-* (also leak-*, timeout-*, oom-*) files, uploaded as fuzz-findings for 30 days. Reproduce with python fuzz/fuzz_x.py crash-<sha>.
  • A hang fails the step too, and leaves its input. libFuzzer is run with -timeout, set by timeout-per-input (25 seconds by default), so an input that never returns is reported as a timeout, fails the target and is saved as a timeout-* file in fuzz-findings. The first hang found (a TLE whose epoch made an SGP4 C routine never return) had surfaced only as the outer per-target backstop killing the process, with no artifact (issue #82). The failure message tells you to look for timeout-* first for a hang and crash-* for a crash. The backstop still exists, for a target that hangs libFuzzer itself.
  • Atheris is installed from one pinned version under --require-hashes with --only-binary, so nothing is built on the runner. It publishes x86_64 manylinux wheels for CPython 3.12 to 3.14 only, so the default Python is 3.14 and runner must be x86_64 Linux. A test fails when the workflow's pin and requirements-dev.in disagree.
  • Add the job to the caller's CI green needs: (or run it on a schedule) so a crash cannot merge unseen. The Hammunition suite's callers run it for 30 seconds on a pull request and 600 seconds weekly.

A minimal caller

jobs:
  fuzz:
    uses: ChiefGyk3D/git-your-ship-together/.github/workflows/python-fuzz.yml@<sha> # vX.Y.Z
    permissions:
      contents: read
    with:
      seconds-per-target: 60
      install-command: pip install -e ".[parse]"   # only when the default is not enough

Inputs (13), read from python-fuzz.yml:

Input Type Default Meaning
python-version string 3.14 Python for the job. Atheris 3.1.0 has wheels for CPython 3.12, 3.13 and 3.14 (x86_64 only); 3.14 is the newest.
fuzz-dir string fuzz Directory searched, recursively, for fuzz targets. A missing directory fails the job.
target-glob string fuzz_*.py Filename pattern (find -name) of a fuzz target under fuzz-dir. No match fails the job.
seconds-per-target number 60 Wall-clock seconds each target runs (libFuzzer's -max_total_time; a fraction is truncated).
timeout-per-input number 25 Seconds libFuzzer allows one input before reporting a timeout (a fraction is truncated).
max-len number 4096 Longest input libFuzzer generates, in bytes (-max_len).
install-command string pip install -e . Shell that installs the project under test, run before Atheris is installed. Callers that need extras override it, e.g. pip install -e ".[parse]".
runner string ubuntu-24.04 Runner label. Must be x86_64 Linux; Atheris publishes no aarch64 wheel and no sdist.
egress-policy string audit harden-runner egress policy - audit logs outbound connections, block allows only allowed-endpoints and extra-allowed-endpoints. Jobs that hold no secret follow egress-policy-secretless instead (EX-0001).
egress-policy-secretless string block harden-runner egress policy for the jobs that hold no stored secret, no OIDC token and no write-scoped or publish-capable token (read-only contents, a SARIF upload at most), and whose output no privileged job consumes - exactly audit or block. Defaults to block since security exception EX-0001 (GitHub-hosted runners in westus2 broke harden-runner block) was closed on 2026-11-02 after harden-runner v2.22.3 passed on westus2; see docs/security/exceptions/. Every job still has the default read-only job token. Set audit to opt out if the defect recurs. Any other job follows egress-policy. Any other value fails the job.
allowed-endpoints string api.github.com:443 files.pythonhosted.org:443 github.com:443 objects.githubusercontent.com:443 pypi.org:443 release-assets.githubusercontent.com:443 harden-runner allow-list for block, space-separated host:port entries. The default is every endpoint this workflow reaches; the runner's own infrastructure needs no entry. Wildcards are not supported and a newline-separated list matches nothing.
extra-allowed-endpoints string empty Appended to allowed-endpoints, for hosts only this repository reaches, such as a private index its install command uses. Same format.
timeout-minutes number 30 Job timeout. Raise it with seconds-per-target when a repository has many targets, since they run one after another.

What it refuses to do

It never holds a token, never treats a missing target as a pass, and never builds Atheris from source on the runner.

Clone this wiki locally