浏览代码

Test tree diffing in `fuzz_object_store` fuzz target

This increases coverage and brings `fuzz_object_store.py` into full
alignment with the Object Store tutorial in the Dulwich docs.
David Lakin 10 月之前
父节点
当前提交
e535d58f0c
共有 2 个文件被更改,包括 43 次插入0 次删除
  1. 12 0
      fuzzing/dictionaries/fuzz_object_store.dict
  2. 31 0
      fuzzing/fuzz-targets/fuzz_object_store.py

+ 12 - 0
fuzzing/dictionaries/fuzz_object_store.dict

@@ -0,0 +1,12 @@
+"_tu"
+"old"
+"\\007\\000\\000\\000\\000\\000\\000\\000"
+"rename_detector"
+"\\000\\000\\000\\000\\000\\000\\000\\000"
+"\\031\\000\\000\\000\\000\\000\\000\\000"
+"\\032\\000\\000\\000\\000\\000\\000\\000"
+"\\001\\000\\000\\000"
+"\\000\\000\\000\\000"
+"\\001\\000"
+"\\032\\000\\000\\000\\000\\000\\000\\000"
+"\\002\\000\\000\\000\\000\\000\\000\\000"

+ 31 - 0
fuzzing/fuzz-targets/fuzz_object_store.py

@@ -1,5 +1,6 @@
 import sys
 import stat
+from io import BytesIO
 
 import atheris
 
@@ -8,6 +9,7 @@ with atheris.instrument_imports():
     from test_utils import EnhancedFuzzedDataProvider, is_expected_exception
     from dulwich.objects import Blob, Tree, Commit, S_IFGITLINK
     from dulwich.errors import ObjectFormatException
+    from dulwich.patch import write_tree_diff
     from dulwich.repo import (
         MemoryRepo,
         InvalidUserIdentity,
@@ -52,6 +54,35 @@ def TestOneInput(data):
         else:
             raise e
 
+    commit2 = Commit()
+    commit2.tree = tree.id
+    commit2.parents = [commit.id]
+    commit2.author = commit.author
+    commit2.committer = commit.committer
+    commit2.commit_time = fdp.ConsumeRandomInt()
+    commit2.commit_timezone = fdp.ConsumeRandomInt()
+    commit2.author_time = fdp.ConsumeRandomInt()
+    commit2.author_timezone = fdp.ConsumeRandomInt()
+    commit2.message = fdp.ConsumeRandomBytes()
+
+    try:
+        blob.data = fdp.ConsumeRandomBytes()
+        repo.object_store.add_object(blob)
+        repo.object_store.add_object(tree)
+        repo.object_store.add_object(commit2)
+        out = BytesIO()
+        write_tree_diff(out, repo.object_store, commit.tree, tree.id)
+    except (InvalidUserIdentity, ObjectFormatException):
+        return -1
+    except ValueError as e:
+        expected_exceptions = [
+            "Unable to handle non-minute offset",
+        ]
+        if is_expected_exception(expected_exceptions, e):
+            return -1
+        else:
+            raise e
+
 
 def main():
     atheris.Setup(sys.argv, TestOneInput)