ci: support safe CUDA archive extraction on Python 3.11
Linux / verify (pull_request) Failing after 30s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-static-cli (pull_request) Skipped
Linux / linux-cli-container (pull_request) Skipped
Linux / release-cli (pull_request) Skipped

This commit is contained in:
Pavlo Ratushnyi
2026-10-05 21:21:01 +02:00
parent 39a0fe00da
commit e5d934a850
3 changed files with 46 additions and 1 deletions
+1
View File
@@ -43,6 +43,7 @@ jobs:
keyless-cuda:
if: github.event_name == 'workflow_dispatch' && github.event.inputs.keyless_gpu == 'true'
needs: verify
runs-on: [self-hosted, linux, x64, strata-gpu]
steps:
- uses: actions/checkout@v4
+26 -1
View File
@@ -6,6 +6,7 @@ redistrib archives are assembly inputs, not a general-purpose CUDA installer.
"""
import argparse
import hashlib
import inspect
import json
import os
from pathlib import Path, PurePosixPath
@@ -53,6 +54,30 @@ def validate_lock(lock, manifest):
raise ValueError('component exceeds download budget')
def extract_members(source, destination, members, *, supports_filter=None):
"""Use tarfile's data policy on both new and older Python runtimes.
Python 3.11 includes ``tarfile.data_filter`` but its ``extractall`` does
not accept the ``filter`` keyword. Pre-filtering every member preserves
the same path, link, mode, and ownership checks there. Fail closed if a
Python runtime has neither API rather than extracting unfiltered data.
"""
if supports_filter is None:
supports_filter = 'filter' in inspect.signature(source.extractall).parameters
if supports_filter:
source.extractall(destination, members=members, filter='data')
return
data_filter = getattr(tarfile, 'data_filter', None)
if data_filter is None:
raise RuntimeError('safe tar extraction requires Python tarfile data_filter support')
safe_members = []
for member in members:
safe_member = data_filter(member, str(destination))
if safe_member is not None:
safe_members.append(safe_member)
source.extractall(destination, members=safe_members)
def extract(archive, destination, root_name):
with tarfile.open(archive, 'r:xz') as source:
members=source.getmembers()
@@ -68,7 +93,7 @@ def extract(archive, destination, root_name):
seen.add(item.name)
if not (item.isdir() or item.isfile() or item.issym() or item.islnk()):
raise ValueError('unsupported archive member')
source.extractall(destination, members=members, filter='data')
extract_members(source, destination, members)
return destination/root_name
+19
View File
@@ -20,6 +20,25 @@ class Tests(unittest.TestCase):
item=tarfile.TarInfo('component/lib/b');item.type=tarfile.SYMTYPE;item.linkname='a';t.addfile(item)
out=m.extract(archive,root/'out','component')
self.assertEqual((out/'lib/b').read_bytes(),b'a')
def test_python311_style_data_filter_fallback(self):
# Python 3.11 has data_filter but extractall(filter=...) is unavailable.
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);archive=root/'test.tar.xz';dest=root/'out'
with tarfile.open(archive,'w:xz') as t:
item=tarfile.TarInfo('component/lib/a');item.size=1;t.addfile(item,io.BytesIO(b'a'))
item=tarfile.TarInfo('component/lib/b');item.type=tarfile.SYMTYPE;item.linkname='a';t.addfile(item)
with tarfile.open(archive,'r:xz') as source:
m.extract_members(source,dest,source.getmembers(),supports_filter=False)
self.assertEqual((dest/'component/lib/b').read_bytes(),b'a')
def test_python311_style_fallback_rejects_escaping_link(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);archive=root/'test.tar.xz';dest=root/'out'
with tarfile.open(archive,'w:xz') as t:
item=tarfile.TarInfo('component/b');item.type=tarfile.SYMTYPE;item.linkname='../../escape';t.addfile(item)
with tarfile.open(archive,'r:xz') as source:
with self.assertRaises(tarfile.FilterError):
m.extract_members(source,dest,source.getmembers(),supports_filter=False)
self.assertFalse((root/'escape').exists())
def test_bad_archive_paths_and_links(self):
for name,link in [('../escape',None),('/escape',None),('other/file',None),('component/b','../../escape')]:
with self.subTest(name=name),tempfile.TemporaryDirectory() as tmp: