3
3
import os
4
4
import tempfile
5
5
from configparser import ParsingError
6
- from utils import is_expected_exception_message
6
+ from utils import is_expected_exception_message , get_max_filename_length
7
+ from git import Repo , GitCommandError , InvalidGitRepositoryError
7
8
8
- if getattr (sys , "frozen" , False ) and hasattr (sys , "_MEIPASS" ):
9
+ if getattr (sys , "frozen" , False ) and hasattr (sys , "_MEIPASS" ): # pragma: no cover
9
10
path_to_bundled_git_binary = os .path .abspath (os .path .join (os .path .dirname (__file__ ), "git" ))
10
11
os .environ ["GIT_PYTHON_GIT_EXECUTABLE" ] = path_to_bundled_git_binary
11
12
12
- with atheris .instrument_imports ():
13
- from git import Repo , GitCommandError , InvalidGitRepositoryError
13
+ if not sys .warnoptions : # pragma: no cover
14
+ # The warnings filter below can be overridden by passing the -W option
15
+ # to the Python interpreter command line or setting the `PYTHONWARNINGS` environment variable.
16
+ import warnings
17
+ import logging
18
+
19
+ # Fuzzing data causes some modules to generate a large number of warnings
20
+ # which are not usually interesting and make the test output hard to read, so we ignore them.
21
+ warnings .simplefilter ("ignore" )
22
+ logging .getLogger ().setLevel (logging .ERROR )
14
23
15
24
16
25
def TestOneInput (data ):
@@ -42,12 +51,12 @@ def TestOneInput(data):
42
51
writer .release ()
43
52
44
53
submodule .update (init = fdp .ConsumeBool (), dry_run = fdp .ConsumeBool (), force = fdp .ConsumeBool ())
45
-
46
54
submodule_repo = submodule .module ()
47
- new_file_path = os . path . join (
48
- submodule_repo . working_tree_dir ,
49
- f"new_file_ { fdp .ConsumeUnicodeNoSurrogates ( fdp . ConsumeIntInRange (1 , 512 )) } " ,
55
+
56
+ new_file_name = fdp . ConsumeUnicodeNoSurrogates (
57
+ fdp .ConsumeIntInRange (1 , max ( 1 , get_max_filename_length ( submodule_repo . working_tree_dir )))
50
58
)
59
+ new_file_path = os .path .join (submodule_repo .working_tree_dir , new_file_name )
51
60
with open (new_file_path , "wb" ) as new_file :
52
61
new_file .write (fdp .ConsumeBytes (fdp .ConsumeIntInRange (1 , 512 )))
53
62
submodule_repo .index .add ([new_file_path ])
@@ -67,16 +76,24 @@ def TestOneInput(data):
67
76
)
68
77
repo .index .commit (f"Removed submodule { submodule_name } " )
69
78
70
- except (ParsingError , GitCommandError , InvalidGitRepositoryError , FileNotFoundError , BrokenPipeError ):
79
+ except (
80
+ ParsingError ,
81
+ GitCommandError ,
82
+ InvalidGitRepositoryError ,
83
+ FileNotFoundError ,
84
+ FileExistsError ,
85
+ IsADirectoryError ,
86
+ NotADirectoryError ,
87
+ BrokenPipeError ,
88
+ ):
71
89
return - 1
72
- except ( ValueError , OSError ) as e :
90
+ except ValueError as e :
73
91
expected_messages = [
74
92
"SHA is empty" ,
75
93
"Reference at" ,
76
94
"embedded null byte" ,
77
95
"This submodule instance does not exist anymore" ,
78
96
"cmd stdin was empty" ,
79
- "File name too long" ,
80
97
]
81
98
if is_expected_exception_message (e , expected_messages ):
82
99
return - 1
@@ -85,6 +102,7 @@ def TestOneInput(data):
85
102
86
103
87
104
def main ():
105
+ atheris .instrument_all ()
88
106
atheris .Setup (sys .argv , TestOneInput )
89
107
atheris .Fuzz ()
90
108
0 commit comments