]> git.proxmox.com Git - mirror_linux-firmware.git/commitdiff
Merge branch 'mlimonci/unicode' into 'main'
authorJosh Boyer <jwboyer@redhat.com>
Tue, 24 Oct 2023 11:20:07 +0000 (11:20 +0000)
committerJosh Boyer <jwboyer@redhat.com>
Tue, 24 Oct 2023 11:20:07 +0000 (11:20 +0000)
Catch unicode decode errors

See merge request kernel-firmware/linux-firmware!37

contrib/process_linux_firmware.py

index 2b7c7f8d5fc3fc17abe6ed35f8ee65da5b55f02d..ab005ee7cc774a35aeac479aec71a2979738108b 100755 (executable)
@@ -44,11 +44,15 @@ def classify_content(content):
 
     for part in msg.walk():
         if part.get_content_type() == "text/plain":
-            body = part.get_payload(decode=True).decode("utf-8")
-            for key in content_types.keys():
-                if key in body:
-                    return content_types[key]
-            break
+            try:
+                body = part.get_payload(decode=True).decode("utf-8")
+                for key in content_types.keys():
+                    if key in body:
+                        return content_types[key]
+                break
+            except UnicodeDecodeError as e:
+                logging.warning("Failed to decode email: %s, treating as SPAM" % e)
+                break
     return ContentType.SPAM