Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
GitPython/fuzzing/fuzz-targets/utils.py at 3.1.59 · gitpython-developers/GitPython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
gitpython-developers
/
GitPython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
998
Star
5.2k
Code
Issues
7
Pull requests
2
Discussions
Actions
Security and quality
35
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Files
Expand file tree
3.1.59
Breadcrumbs
GitPython
/
fuzzing
/
fuzz-targets
/
utils.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
122 lines (100 loc) · 4.69 KB
3.1.59
Breadcrumbs
GitPython
/
fuzzing
/
fuzz-targets
/
utils.py
Copy path
Top
File metadata and controls
Code
Blame
122 lines (100 loc) · 4.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import
atheris
# pragma: no cover
import
os
# pragma: no cover
import
re
# pragma: no cover
import
traceback
# pragma: no cover
import
sys
# pragma: no cover
from
typing
import
Set
,
Tuple
,
List
# pragma: no cover
@
atheris
.
instrument_func
def
is_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
()
for
error
in
error_message_list
:
if
error
.
lower
()
in
exception_message
:
return
True
return
False
@
atheris
.
instrument_func
def
get_max_filename_length
(
path
:
str
)
->
int
:
# pragma: no cover
"""
Get the maximum filename length for the filesystem containing the given path.
Args:
path (str): The path to check the filesystem for.
Returns:
int: The maximum filename length.
"""
return
os
.
pathconf
(
path
,
"PC_NAME_MAX"
)
@
atheris
.
instrument_func
def
read_lines_from_file
(
file_path
:
str
)
->
list
:
"""Read lines from a file and return them as a list."""
try
:
with
open
(
file_path
,
"r"
)
as
f
:
return
[
line
.
strip
()
for
line
in
f
if
line
.
strip
()]
except
FileNotFoundError
:
print
(
f"File not found:
{
file_path
}
"
)
return
[]
except
IOError
as
e
:
print
(
f"Error reading file
{
file_path
}
:
{
e
}
"
)
return
[]
@
atheris
.
instrument_func
def
load_exception_list
(
file_path
:
str
=
"explicit-exceptions-list.txt"
)
->
Set
[
Tuple
[
str
,
str
]]:
"""Load and parse the exception list from a default or specified file."""
try
:
bundle_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
full_path
=
os
.
path
.
join
(
bundle_dir
,
file_path
)
lines
=
read_lines_from_file
(
full_path
)
exception_list
:
Set
[
Tuple
[
str
,
str
]]
=
set
()
for
line
in
lines
:
match
=
re
.
match
(
r"(.+):(\d+):"
,
line
)
if
match
:
file_path
:
str
=
match
.
group
(
1
).
strip
()
line_number
:
str
=
str
(
match
.
group
(
2
).
strip
())
exception_list
.
add
((
file_path
,
line_number
))
return
exception_list
except
Exception
as
e
:
print
(
f"Error loading exception list:
{
e
}
"
)
return
set
()
@
atheris
.
instrument_func
def
match_exception_with_traceback
(
exception_list
:
Set
[
Tuple
[
str
,
str
]],
exc_traceback
)
->
bool
:
"""Match exception traceback with the entries in the exception list."""
for
filename
,
lineno
,
_
,
_
in
traceback
.
extract_tb
(
exc_traceback
):
for
file_pattern
,
line_pattern
in
exception_list
:
# Ensure filename and line_number are strings for regex matching
if
re
.
fullmatch
(
file_pattern
,
filename
)
and
re
.
fullmatch
(
line_pattern
,
str
(
lineno
)):
return
True
return
False
@
atheris
.
instrument_func
def
check_exception_against_list
(
exc_traceback
,
exception_file
:
str
=
"explicit-exceptions-list.txt"
)
->
bool
:
"""Check if the exception traceback matches any entry in the exception list."""
exception_list
=
load_exception_list
(
exception_file
)
return
match_exception_with_traceback
(
exception_list
,
exc_traceback
)
@
atheris
.
instrument_func
def
handle_exception
(
e
:
Exception
)
->
int
:
"""Encapsulate exception handling logic for reusability."""
exc_traceback
=
e
.
__traceback__
if
check_exception_against_list
(
exc_traceback
):
return
-
1
else
:
raise
e
@
atheris
.
instrument_func
def
setup_git_environment
()
->
None
:
"""Set up the environment variables for Git."""
bundle_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
if
getattr
(
sys
,
"frozen"
,
False
)
and
hasattr
(
sys
,
"_MEIPASS"
):
# pragma: no cover
bundled_git_binary_path
=
os
.
path
.
join
(
bundle_dir
,
"git"
)
os
.
environ
[
"GIT_PYTHON_GIT_EXECUTABLE"
]
=
bundled_git_binary_path
if
not
sys
.
warnoptions
:
# pragma: no cover
# The warnings filter below can be overridden by passing the -W option
# to the Python interpreter command line or setting the `PYTHONWARNINGS` environment variable.
import
warnings
import
logging
# Fuzzing data causes some modules to generate a large number of warnings
# which are not usually interesting and make the test output hard to read, so we ignore them.
warnings
.
simplefilter
(
"ignore"
)
logging
.
getLogger
().
setLevel
(
logging
.
ERROR
)
You can’t perform that action at this time.