You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by ar...@apache.org on 2026/04/09 09:22:53 UTC

(tooling-trusted-releases) branch arm updated: #981 - return accumulator variable instead of 0 when extracting archives

This is an automated email from the ASF dual-hosted git repository.

arm pushed a commit to branch arm
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git


The following commit(s) were added to refs/heads/arm by this push:
     new 79ed3f93 #981 - return accumulator variable instead of 0 when extracting archives
79ed3f93 is described below

commit 79ed3f9306f52aed004fb78463161c2fb9feacf6
Author: Alastair McFarlane <ar...@apache.org>
AuthorDate: Thu Apr 9 10:22:39 2026 +0100

    #981 - return accumulator variable instead of 0 when extracting archives
---
 atr/archives.py | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/atr/archives.py b/atr/archives.py
index 216e8512..91927db6 100644
--- a/atr/archives.py
+++ b/atr/archives.py
@@ -139,14 +139,19 @@ def _tar_archive_extract_member(  # noqa: C901
     track_files: bool | set[str] = False,
     extracted_paths: list[str] = [],
 ) -> tuple[int, list[str]]:
+    """
+    Extract a single member from a tar archive.
+
+    `total_extracted` is an accumulator and should return itself if nothing is extracted
+    """
     member_basename = os.path.basename(member.name)
     if member_basename.startswith("._"):
         # Metadata convention
-        return 0, extracted_paths
+        return total_extracted, extracted_paths
 
     # Skip any character device, block device, or FIFO
     if member.isdev():
-        return 0, extracted_paths
+        return total_extracted, extracted_paths
 
     # Only track files that pass the path safety check
     if track_files and isinstance(track_files, set) and (member_basename in track_files):
@@ -165,7 +170,7 @@ def _tar_archive_extract_member(  # noqa: C901
         # Ensure the path is safe before extracting
         if _safe_path(extract_dir, member.name) is None:
             log.warning(f"Skipping potentially unsafe path: {member.name}")
-            return 0, extracted_paths
+            return total_extracted, extracted_paths
         archive.extract_member(member, extract_dir, numeric_owner=True, tar_filter="fully_trusted")
 
     elif member.isfile():
@@ -290,6 +295,11 @@ def _zip_archive_extract_member(
     track_files: bool | set[str] = False,
     extracted_paths: list[str] = [],
 ) -> tuple[int, list[str]]:
+    """
+    Extract a single member from a zip archive.
+
+    `total_extracted` is an accumulator and should return itself if nothing is extracted
+    """
     member_basename = os.path.basename(member.name)
 
     # Only track files that pass the path safety check
@@ -298,7 +308,7 @@ def _zip_archive_extract_member(
             extracted_paths.append(member.name)
 
     if member_basename.startswith("._"):
-        return 0, extracted_paths
+        return total_extracted, extracted_paths
 
     if member.isfile() and ((total_extracted + member.size) > max_size):
         raise ExtractionError(
@@ -310,7 +320,7 @@ def _zip_archive_extract_member(
         target_path = _safe_path(extract_dir, member.name)
         if target_path is None:
             log.warning(f"Skipping potentially unsafe path: {member.name}")
-            return 0, extracted_paths
+            return total_extracted, extracted_paths
         os.makedirs(target_path, exist_ok=True)
         return total_extracted, extracted_paths
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org