|
| 1 | +# ruff: noqa: E402 |
1 | 2 | import atheris
|
2 | 3 | import sys
|
3 | 4 | import os
|
| 5 | +import traceback |
4 | 6 | import tempfile
|
5 | 7 | from configparser import ParsingError
|
6 |
| -from utils import is_expected_exception_message, get_max_filename_length |
| 8 | +from utils import get_max_filename_length |
| 9 | +import re |
| 10 | + |
| 11 | +bundle_dir = os.path.dirname(os.path.abspath(__file__)) |
7 | 12 |
|
8 | 13 | if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): # pragma: no cover
|
9 |
| - path_to_bundled_git_binary = os.path.abspath(os.path.join(os.path.dirname(__file__), "git")) |
10 |
| - os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = path_to_bundled_git_binary |
| 14 | + bundled_git_binary_path = os.path.join(bundle_dir, "git") |
| 15 | + os.environ["GIT_PYTHON_GIT_EXECUTABLE"] = bundled_git_binary_path |
11 | 16 |
|
12 | 17 | from git import Repo, GitCommandError, InvalidGitRepositoryError
|
13 | 18 |
|
| 19 | + |
| 20 | +def load_exception_list(file_path): |
| 21 | + """Load and parse the exception list from a file.""" |
| 22 | + try: |
| 23 | + with open(file_path, "r") as file: |
| 24 | + lines = file.readlines() |
| 25 | + exception_list = set() |
| 26 | + for line in lines: |
| 27 | + match = re.match(r"(.+):(\d+):", line) |
| 28 | + if match: |
| 29 | + file_path = match.group(1).strip() |
| 30 | + line_number = int(match.group(2).strip()) |
| 31 | + exception_list.add((file_path, line_number)) |
| 32 | + return exception_list |
| 33 | + except FileNotFoundError: |
| 34 | + print("File not found: %s", file_path) |
| 35 | + return set() |
| 36 | + except Exception as e: |
| 37 | + print("Error loading exception list: %s", e) |
| 38 | + return set() |
| 39 | + |
| 40 | + |
| 41 | +def check_exception_against_list(exception_list, exc_traceback): |
| 42 | + """Check if the exception traceback matches any entry in the exception list.""" |
| 43 | + for filename, lineno, _, _ in traceback.extract_tb(exc_traceback): |
| 44 | + if (filename, lineno) in exception_list: |
| 45 | + return True |
| 46 | + return False |
| 47 | + |
| 48 | + |
14 | 49 | if not sys.warnoptions: # pragma: no cover
|
15 | 50 | # The warnings filter below can be overridden by passing the -W option
|
16 | 51 | # to the Python interpreter command line or setting the `PYTHONWARNINGS` environment variable.
|
@@ -89,17 +124,14 @@ def TestOneInput(data):
|
89 | 124 | BrokenPipeError,
|
90 | 125 | ):
|
91 | 126 | return -1
|
92 |
| - except ValueError as e: |
93 |
| - expected_messages = [ |
94 |
| - "SHA is empty", |
95 |
| - "Reference at", |
96 |
| - "embedded null byte", |
97 |
| - "This submodule instance does not exist anymore", |
98 |
| - "cmd stdin was empty", |
99 |
| - ] |
100 |
| - if is_expected_exception_message(e, expected_messages): |
| 127 | + except Exception as e: |
| 128 | + exc_traceback = e.__traceback__ |
| 129 | + exception_list = load_exception_list(os.path.join(bundle_dir, "explicit-exceptions-list.txt")) |
| 130 | + if check_exception_against_list(exception_list, exc_traceback): |
| 131 | + print("Exception matches an entry in the exception list.") |
101 | 132 | return -1
|
102 | 133 | else:
|
| 134 | + print("Exception does not match any entry in the exception list.") |
103 | 135 | raise e
|
104 | 136 |
|
105 | 137 |
|
|
0 commit comments