fix(ci): qualify on the pinned Python and retain immutable release bundles
Device Core qualification / qualify (push) Successful in 5m51s
Device Core qualification / qualify (push) Successful in 5m51s
This commit is contained in:
@@ -228,6 +228,41 @@ def safe_tar_member(member: tarfile.TarInfo):
|
||||
die("artifact contains AppleDouble metadata")
|
||||
|
||||
|
||||
def extract_validated_files(archive, extraction_root):
|
||||
"""Materialize only regular data, also on Python before tar filters existed."""
|
||||
if extraction_root.is_symlink() or not extraction_root.is_dir() or any(extraction_root.iterdir()):
|
||||
die("artifact extraction requires an empty private directory")
|
||||
root = extraction_root.resolve(strict=True)
|
||||
members = archive.getmembers()
|
||||
if len(members) > 65536 or sum(item.size for item in members) > MAX_ARTIFACT_BYTES:
|
||||
die("artifact expanded size/count rejected")
|
||||
normalized = set()
|
||||
files = set()
|
||||
for member in members:
|
||||
safe_tar_member(member)
|
||||
path = PurePosixPath(member.name)
|
||||
name = path.as_posix()
|
||||
if member.name.rstrip("/") != name or name in normalized:
|
||||
die("artifact contains noncanonical or duplicate paths")
|
||||
normalized.add(name)
|
||||
if member.isfile():
|
||||
files.add(name)
|
||||
for member in members:
|
||||
if any(str(parent) in files for parent in PurePosixPath(member.name).parents):
|
||||
die("artifact file is used as a directory")
|
||||
# All members are checked before any output. Never apply archive ownership,
|
||||
# links, devices or special mode bits; never invoke extract/extractall.
|
||||
for member in members:
|
||||
destination = root.joinpath(*PurePosixPath(member.name).parts)
|
||||
if member.isdir():
|
||||
destination.mkdir(parents=True, exist_ok=True, mode=0o755)
|
||||
else:
|
||||
destination.parent.mkdir(parents=True, exist_ok=True, mode=0o755)
|
||||
with archive.extractfile(member) as source, destination.open("xb") as output:
|
||||
shutil.copyfileobj(source, output)
|
||||
destination.chmod(0o755 if member.mode & 0o111 else 0o644)
|
||||
|
||||
|
||||
def load_artifact(artifact: Path, extraction_root: Path):
|
||||
artifact = artifact.resolve(strict=True)
|
||||
if artifact.parent != INBOX_ROOT.resolve(strict=True):
|
||||
@@ -248,7 +283,7 @@ def load_artifact(artifact: Path, extraction_root: Path):
|
||||
die("artifact top-level contract is incomplete")
|
||||
if any(name.split("/", 1)[0] not in required for name in seen):
|
||||
die("artifact contains an unexpected top-level member")
|
||||
archive.extractall(extraction_root, filter="data")
|
||||
extract_validated_files(archive, extraction_root)
|
||||
|
||||
manifest = parse_manifest(
|
||||
(extraction_root / "manifest.env").read_text(encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user