]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Python fuzzing. (#123)
authorNicolas Patry <patry.nicolas@protonmail.com>
Wed, 7 Dec 2022 16:04:03 +0000 (17:04 +0100)
committerGitHub <noreply@github.com>
Wed, 7 Dec 2022 16:04:03 +0000 (17:04 +0100)
bindings/python/fuzz.py [new file with mode: 0644]

diff --git a/bindings/python/fuzz.py b/bindings/python/fuzz.py
new file mode 100644 (file)
index 0000000..682152a
--- /dev/null
@@ -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()