From 88e4b9008d45682ee1db2d9e9c3574bb3c23aabe Mon Sep 17 00:00:00 2001 From: Matt Schwager Date: Tue, 23 Apr 2024 08:11:57 -0400 Subject: [PATCH] Move OSS-Fuzz target file under tests --- pyproject.toml | 3 +++ tests/fuzzers/loads_fuzzer.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/fuzzers/loads_fuzzer.py diff --git a/pyproject.toml b/pyproject.toml index 29b4cad..fbcabb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,9 @@ doc = [ benchmarks = [ "pytest-benchmark==4.0.0", ] +fuzz = [ + "atheris", +] [project.scripts] cbor2 = "cbor2.tool:main" diff --git a/tests/fuzzers/loads_fuzzer.py b/tests/fuzzers/loads_fuzzer.py new file mode 100644 index 0000000..04ba81e --- /dev/null +++ b/tests/fuzzers/loads_fuzzer.py @@ -0,0 +1,22 @@ +import sys +import atheris + +# _cbor2 ensures the C library is imported +from _cbor2 import loads + + +def test_one_input(data: bytes): + try: + loads(data) + except Exception: + # We're searching for memory corruption, not Python exceptions + pass + + +def main(): + atheris.Setup(sys.argv, test_one_input) + atheris.Fuzz() + + +if __name__ == "__main__": + main()