fix: check zip member paths with core.ziptools

The data directory refresh dropped any name containing .. in silence,
wrote a backslash as a filename character and let a drive letter or a
backslash traversal through. The pack integrity check flagged Read..me
as a traversal. Both now use safe_member_parts, and an unsafe member
fails the refresh of its key instead of thinning the tree.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:00:53 +01:00
1 parent 79e5eae036
commit 8bc497cf15
5 files changed
+62 -25

No files matched your search

+7 -8
View File
@@ -18,6 +18,7 @@ from pathlib import Path
from core import upstream
from core.artifacts import file_lock as _file_lock, write_text_atomic
from core.upstream import remote_etag as _get_remote_etag
from core.ziptools import safe_member_parts
from model.registry import VERSIONS_FILE, load_versions
@@ -321,16 +322,13 @@ def _download_and_extract_zip(
for info in zf.infolist():
if info.is_dir():
continue
name = info.filename
if ".." in name or name.startswith("/"):
continue
parts = safe_member_parts(info)
# strip leading path components
parts = name.split("/")
if strip_components > 0:
if len(parts) <= strip_components:
continue
parts = parts[strip_components:]
name = "/".join(parts)
name = "/".join(parts)
# skip excludes (check against stripped path)
top = parts[0] if parts else ""
if top in exclude:
@@ -512,13 +510,14 @@ def _refresh_entry(
source_url, source_path, local_cache, exclude, measured=archive_sizes.append
)
# An archive that reads but holds nothing under the path is the same on
# every try: only a failed or unreadable download is tried again.
# An archive that reads but holds nothing under the path, or a member
# core.ziptools refuses (ValueError), is the same on every try: only a
# failed or unreadable download is tried again.
for attempt, wait in enumerate((*DOWNLOAD_RETRY_WAITS, None), start=1):
try:
file_count = fetch()
break
except NothingExtractedError as exc:
except (NothingExtractedError, ValueError) as exc:
log.warning("[%s] download failed: %s", key, exc)
return None
except _TRANSIENT as exc:
+7 -7
View File
@@ -13,6 +13,7 @@ from typing import TYPE_CHECKING, TypedDict
from core.artifacts import build_timestamp
from packs.paths import MEDIA_MARKER, has_path_conflict
from core.ziptools import build_zip_contents_index
from core.ziptools import safe_member_parts
from resolve.nativemode import digest_algorithm, platform_mode
from resolve.validation import (
baseline_verdict, digest_verdict, inner_rom_check, inner_rom_data_check,
@@ -510,13 +511,12 @@ def _structural_errors(zf: zipfile.ZipFile, zip_set: set) -> list[str]:
dupes = sum(1 for c in Counter(zf.namelist()).values() if c > 1)
if dupes:
errors.append(f"{dupes} duplicate entries")
for n in zip_set:
if "//" in n:
errors.append(f"double slash: {n}")
if n.startswith("/"):
errors.append(f"absolute path: {n}")
if ".." in n:
errors.append(f"path traversal: {n}")
errors.extend(f"double slash: {n}" for n in zip_set if "//" in n)
for info in zf.infolist():
try:
safe_member_parts(info)
except ValueError as exc:
errors.append(str(exc))
# Zero-byte check (exclude Dolphin GraphicMods markers)
errors.extend(