From 8731ae181db0e6c81e360ccfab89e19de33bd3a6 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Wed, 7 Dec 2022 17:04:03 +0100 Subject: [PATCH] Python fuzzing. (#123) --- bindings/python/fuzz.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bindings/python/fuzz.py diff --git a/bindings/python/fuzz.py b/bindings/python/fuzz.py new file mode 100644 index 0000000..682152a --- /dev/null +++ b/bindings/python/fuzz.py @@ -0,0 +1,35 @@ +import datetime +import sys +import tempfile +from collections import defaultdict + +import atheris + + +with atheris.instrument_imports(): + from safetensors.torch import load_file + + +EXCEPTIONS = defaultdict(int) +START = datetime.datetime.now() +DT = datetime.timedelta(seconds=30) + + +def TestOneInput(data): + global START + with tempfile.NamedTemporaryFile() as f: + f.write(data) + f.seek(0) + try: + load_file(f.name, device=0) + except Exception as e: + EXCEPTIONS[str(e)] += 1 + + if datetime.datetime.now() - START > DT: + for e, n in EXCEPTIONS.items(): + print(e, n) + START = datetime.datetime.now() + + +atheris.Setup(sys.argv, TestOneInput) +atheris.Fuzz() -- 2.43.0