From: Nicolas Patry Date: Wed, 7 Dec 2022 16:04:03 +0000 (+0100) Subject: Python fuzzing. (#123) X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=8731ae181db0e6c81e360ccfab89e19de33bd3a6;p=safetensors.git Python fuzzing. (#123) --- 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()