diff mbox series

[3/3] goh1_file: deal with false positives from is_zipfile

Message ID 20260413095918.20804-3-yann.dirson@vates.tech
State New
Headers show
Series [1/3] add_tasks: use sets to dedup from debug output | expand

Commit Message

Yann Dirson April 13, 2026, 9:59 a.m. UTC
This function is known https://github.com/python/cpython/issues/72680 for
false-positives.  With python 3.13.5 there is one with
https://vault.almalinux.org/10.0/CRB/x86_64_v2/os/Packages/jdom2-2.0.6.1-8.el10.noarch.rpm

The double "is_zipfile = False" is redundant but likely more clear.

Signed-off-by: Yann Dirson <yann.dirson@vates.tech>
---
 lib/bb/utils.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 366836bfc..aeeb3f2ee 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -694,14 +694,19 @@  def goh1_file(filename):
     import zipfile
 
     lines = []
+    is_zipfile = False
     if zipfile.is_zipfile(filename):
-        with zipfile.ZipFile(filename) as archive:
-            for fn in sorted(archive.namelist()):
-                method = hashlib.sha256()
-                method.update(archive.read(fn))
-                hash = method.hexdigest()
-                lines.append("%s  %s\n" % (hash, fn))
-    else:
+        try:
+            with zipfile.ZipFile(filename) as archive:
+                for fn in sorted(archive.namelist()):
+                    method = hashlib.sha256()
+                    method.update(archive.read(fn))
+                    hash = method.hexdigest()
+                    lines.append("%s  %s\n" % (hash, fn))
+            is_zipfile = True
+        except zipfile.BadZipFile:
+            is_zipfile = False
+    if not is_zipfile:
         hash = _hasher(hashlib.sha256(), filename)
         lines.append("%s  go.mod\n" % hash)
     method = hashlib.sha256()