fix: name an unreadable nested archive as cause

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 00:20:03 +01:00
1 parent 387ca39a9d
commit 0be045f95b
2 files changed
+27 -3

No files matched your search

+7 -3
View File
@@ -339,22 +339,26 @@ def _check_member_hash(
with zf.open(member) as f:
computed = stream_hashes(f, frozenset({"md5", "sha1", "crc32"}))
unreadable: list[Exception] = []
def composite() -> str | None:
# Recalbox's Md5Composite, over the sorted members of a ZIP.
if not member.endswith(".zip"):
return None
import io
try:
return md5_composite_of(io.BytesIO(zf.read(member)))
except (zipfile.BadZipFile, OSError) as exc:
print(f" {member}: no member digest ({exc})", file=sys.stderr)
unreadable.append(exc)
return None
if digest_verdict(
file_entry, zf.getinfo(member).file_size, lambda: computed, mode, rule, composite
):
return None
# Only a composite-only entry has the member digest as its one answer:
# elsewhere the container md5 is the comparison that failed.
if unreadable and file_entry.get("zip_digest") == "composite":
return f"{member}: unreadable nested archive ({unreadable[0]})"
return f"{member}: {mode} {computed[mode]} != declared {declared}"
def _repo_satisfies_declaration(
+20
View File
@@ -121,6 +121,26 @@ class PackIntegrityChecksTheMember(unittest.TestCase):
self.assertIsNone(self._verdict(members, {**entry, "md5": ["0" * 32, md5.upper()]}))
self.assertIsNotNone(self._verdict(members, {**entry, "md5": md5[:29]}))
def test_an_unreadable_nested_archive_is_the_reason(self):
"""A composite entry over a member that is no ZIP reported a container
md5 mismatch, a comparison Recalbox never makes, and printed the real
cause to stderr where no caller of the errors list saw it."""
import contextlib
import io
from packs.integrity import _check_member_hash
pack = io.BytesIO()
with zipfile.ZipFile(pack, "w") as zf:
zf.writestr("bios/dragon32.zip", b"not a zip")
entry = {"name": "dragon32.zip", "md5": "0" * 32, "zip_digest": "composite"}
stderr = io.StringIO()
with zipfile.ZipFile(pack) as zf, contextlib.redirect_stderr(stderr):
error = _check_member_hash(zf, "bios/dragon32.zip", entry, "md5")
self.assertIsNotNone(error)
self.assertIn("bios/dragon32.zip: unreadable nested archive (", error)
self.assertEqual(stderr.getvalue(), "")
class TheMemberIndexIsCachedByContent(unittest.TestCase):
"""Each pipeline step that resolves a zipped_file decompressed all 54 845