Skip to content

Fuzzing support for Python projects? #4121

@Zac-HD

Description

@Zac-HD

I'm a core developer of Hypothesis, the property-based testing library for Python. Hypothesis is secretly a structured fuzzer, and in March I added support for treating arbitrary property-based tests as fuzz targets.

It would be lovely to apply this toolchain to CPython (see here, and here), write fuzzable tests for pip, fuzz existing tests for foundational tools like Numpy/Mercurial/PyPy, and so on. The only catch is that it's unclear to me whether, and if so how, Python projects are actually supported in OSS-FUZZ!

For example, to exercise the Python JSON module with python-afl:

import json, os, sys
import afl
from hypothesis import given, strategies as st

@given(st.recursive(
    st.none() | st.booleans() | st.integers() | st.floats(allow_nan=False) | st.text(),
    lambda x: st.lists(x) | st.dictionaries(st.text(), x)
))
def test_json_rountrip(x):
    assert x == json.loads(json.dumps(x))

if __name__ == "__main__":
    fuzz_target = test_json_rountrip.hypothesis.fuzz_one_input
    afl.init()
    fuzz_target(sys.stdin.buffer)
    os._exit(0)

If upstream support in Hypothesis would make OSS-FUZZ integration easier, I would be very happy to add whatever interface we decide on 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions