Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Submodules Fuzz Target#1919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletionsfuzzing/fuzz-targets/fuzz_submodule.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
importatheris
importsys
importos
importtempfile
fromconfigparserimportParsingError
fromutilsimportis_expected_exception_message

ifgetattr(sys,"frozen",False)andhasattr(sys,"_MEIPASS"):
path_to_bundled_git_binary=os.path.abspath(os.path.join(os.path.dirname(__file__),"git"))
os.environ["GIT_PYTHON_GIT_EXECUTABLE"]=path_to_bundled_git_binary

withatheris.instrument_imports():
fromgitimportRepo,GitCommandError,InvalidGitRepositoryError


defTestOneInput(data):
fdp=atheris.FuzzedDataProvider(data)

withtempfile.TemporaryDirectory()asrepo_temp_dir:
repo=Repo.init(path=repo_temp_dir)
repo.index.commit("Initial commit")

try:
withtempfile.TemporaryDirectory()assubmodule_temp_dir:
sub_repo=Repo.init(submodule_temp_dir,bare=fdp.ConsumeBool())
sub_repo.index.commit(fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1,512)))

submodule_name=f"submodule_{fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1,512))}"
submodule_path=os.path.join(repo.working_tree_dir,submodule_name)
submodule_url=sub_repo.git_dir

submodule=repo.create_submodule(submodule_name,submodule_path,url=submodule_url)
repo.index.commit(f"Added submodule{submodule_name}")

withsubmodule.config_writer()aswriter:
key_length=fdp.ConsumeIntInRange(1,max(1,fdp.remaining_bytes()))
value_length=fdp.ConsumeIntInRange(1,max(1,fdp.remaining_bytes()))

writer.set_value(
fdp.ConsumeUnicodeNoSurrogates(key_length),fdp.ConsumeUnicodeNoSurrogates(value_length)
)
writer.release()

submodule.update(init=fdp.ConsumeBool(),dry_run=fdp.ConsumeBool(),force=fdp.ConsumeBool())

submodule_repo=submodule.module()
new_file_path=os.path.join(
submodule_repo.working_tree_dir,
f"new_file_{fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1,512))}",
)
withopen(new_file_path,"wb")asnew_file:
new_file.write(fdp.ConsumeBytes(fdp.ConsumeIntInRange(1,512)))
submodule_repo.index.add([new_file_path])
submodule_repo.index.commit("Added new file to submodule")

repo.submodule_update(recursive=fdp.ConsumeBool())
submodule_repo.head.reset(commit="HEAD~1",working_tree=fdp.ConsumeBool(),head=fdp.ConsumeBool())
# Use fdp.PickValueInList to ensure at least one of 'module' or 'configuration' is True
module_option_value,configuration_option_value=fdp.PickValueInList(
[(True,False), (False,True), (True,True)]
)
submodule.remove(
module=module_option_value,
configuration=configuration_option_value,
dry_run=fdp.ConsumeBool(),
force=fdp.ConsumeBool(),
)
repo.index.commit(f"Removed submodule{submodule_name}")

except (ParsingError,GitCommandError,InvalidGitRepositoryError,FileNotFoundError,BrokenPipeError):
return-1
except (ValueError,OSError)ase:
expected_messages= [
"SHA is empty",
"Reference at",
"embedded null byte",
"This submodule instance does not exist anymore",
"cmd stdin was empty",
"File name too long",
]
ifis_expected_exception_message(e,expected_messages):
return-1
else:
raisee


defmain():
atheris.Setup(sys.argv,TestOneInput)
atheris.Fuzz()


if__name__=="__main__":
main()
22 changes: 22 additions & 0 deletionsfuzzing/fuzz-targets/utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
importatheris# pragma: no cover
fromtypingimportList# pragma: no cover


@atheris.instrument_func
defis_expected_exception_message(exception:Exception,error_message_list:List[str])->bool:# pragma: no cover
"""
Checks if the message of a given exception matches any of the expected error messages, case-insensitively.
Args:
exception (Exception): The exception object raised during execution.
error_message_list (List[str]): A list of error message substrings to check against the exception's message.
Returns:
bool: True if the exception's message contains any of the substrings from the error_message_list,
case-insensitively, otherwise False.
"""
exception_message=str(exception).lower()
forerrorinerror_message_list:
iferror.lower()inexception_message:
returnTrue
returnFalse

[8]ページ先頭

©2009-2025 Movatter.jp