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

juergbi pushed a commit to branch jbilleter/tar
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 07cb7a966dde6cf6808482dd78429f80ff51452b
Author: Jürg Billeter <[email protected]>
AuthorDate: Sat Aug 29 18:37:35 2026 +0200

    tar.py: Use `tar` extraction filter also on Python < 3.12
    
    This aligns the behavior across Python versions, offering some
    protection from unusual and possibly malicious tar files. On Python
    versions lower than 3.12, this uses the imported copy of `tarfile.py`.
---
 src/buildstream/plugins/sources/tar.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/buildstream/plugins/sources/tar.py 
b/src/buildstream/plugins/sources/tar.py
index 040b5c48d..91185a733 100644
--- a/src/buildstream/plugins/sources/tar.py
+++ b/src/buildstream/plugins/sources/tar.py
@@ -63,11 +63,16 @@ documentation.
 import functools
 import os
 import sys
-import tarfile
 from contextlib import contextmanager
 from tempfile import TemporaryFile
 from typing import Optional
 
+# We require the extraction filter support introduced in Python 3.12
+if sys.version_info >= (3, 12):
+    import tarfile
+else:
+    from . import _tarfile as tarfile
+
 from buildstream import DownloadableFileSource, SourceError
 from buildstream import utils
 
@@ -150,10 +155,7 @@ class TarSource(DownloadableFileSource):
                     member = filter_function(member, directory)
                     if member is not None:
                         filtered_members.append(member)
-                if sys.version_info >= (3, 12):
-                    tar.extractall(path=directory, members=filtered_members, 
filter="tar")
-                else:
-                    tar.extractall(path=directory, members=filtered_members)
+                tar.extractall(path=directory, members=filtered_members, 
filter="tar")
 
         except (tarfile.TarError, OSError) as e:
             raise SourceError("{}: Error staging source: {}".format(self, e)) 
from e

Reply via email to