Skip to content

Commit f897fb6

Browse files
authored
fix: handle all tarfile extract errors (#1206)
Now handle the base tarfile error class to catch all errors with extracting tarfiles when downloading source code. Signed-off-by: Carl Flottmann <[email protected]>
1 parent 1b38c20 commit f897fb6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/macaron/slsa_analyzer/checks/detect_malicious_metadata_check.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ def analyze_source(
157157
return {analyzer.heuristic: result}, detail_info
158158

159159
except SourceCodeError as error:
160-
error_msg = f"Unable to perform source code analysis: {error}"
161-
logger.debug(error_msg)
162-
raise HeuristicAnalyzerValueError(error_msg) from error
160+
logger.debug("Unable to perform source code analysis: %s", error)
161+
return {analyzer.heuristic: HeuristicResult.SKIP}, {}
163162

164163
def evaluate_heuristic_results(
165164
self, heuristic_results: dict[Heuristics, HeuristicResult]

src/macaron/slsa_analyzer/package_registry/pypi_registry.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ def download_package_sourcecode(self, url: str) -> str:
268268
try:
269269
with tarfile.open(source_file, "r:gz") as sourcecode_tar:
270270
sourcecode_tar.extractall(temp_dir, filter="data")
271-
except tarfile.ReadError as read_error:
272-
self.cleanup_sourcecode_directory(temp_dir, f"Error reading source code tar file: {read_error}", read_error)
271+
except tarfile.TarError as tar_error:
272+
self.cleanup_sourcecode_directory(
273+
temp_dir, f"Error extracting source code tar file: {tar_error}", tar_error
274+
)
273275

274276
os.remove(source_file)
275277

0 commit comments

Comments
 (0)