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

+12
View File
@@ -355,6 +355,18 @@ class APackForAndroidHidesItsMedia(PackCountFixture):
errors = packverify._structural_errors(archive, set(archive.namelist()))
self.assertEqual(errors, ["zero-byte: empty.bin"])
def test_the_integrity_check_reads_paths_like_core_ziptools(self):
""""Read..me" was reported as a traversal, a backslash one was not."""
from packs import integrity as packverify
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "w") as archive:
archive.writestr("Docs/Read..me.txt", b"r")
archive.writestr("..\\escape.bin", b"x")
with zipfile.ZipFile(buffer) as archive:
errors = packverify._structural_errors(archive, set(archive.namelist()))
self.assertEqual(errors, ["ZIP traversal detected: ../escape.bin"])
def test_a_platform_without_android_gets_none(self):
self.assertEqual(datatrees.pack_markers("demo", None, str(self.platforms)), ())
+20
View File
@@ -69,6 +69,26 @@ class RefreshConcurrency(unittest.TestCase):
leftovers = [p.name for p in self.cache.parent.iterdir() if p.name != "pak"]
self.assertEqual(leftovers, [])
def test_members_follow_the_core_ziptools_rule(self):
"""A name with ".." inside a segment was dropped in silence, and a
backslash member became a file named with the backslash."""
payload = _zip_bytes({"Docs/Read..me.txt": b"r", "sub\\a.bin": b"a"})
with mock.patch.object(
datadirs.urllib.request, "urlopen", lambda *a, **k: _Response(payload)
):
count = datadirs._download_and_extract_zip("https://x/pak.zip", str(self.cache))
self.assertEqual(count, 2)
self.assertEqual((self.cache / "Docs" / "Read..me.txt").read_bytes(), b"r")
self.assertEqual((self.cache / "sub" / "a.bin").read_bytes(), b"a")
def test_a_traversing_member_refuses_the_archive(self):
payload = _zip_bytes({"a.bin": b"a", "..\\escape.bin": b"x"})
with mock.patch.object(
datadirs.urllib.request, "urlopen", lambda *a, **k: _Response(payload)
), self.assertRaises(ValueError):
datadirs._download_and_extract_zip("https://x/pak.zip", str(self.cache))
self.assertFalse(self.cache.exists())
def test_refresh_holds_the_directory_lock(self):
import fcntl