Browse Source

Don't crash when reading corrupt 3MF files

Otherwise it would crash with a BadZipFile error. We should be robust against that. This will trigger a generic message that we couldn't read that file to the user, and put more information in the log.

Fixes Sentry issue CURA-NH.
Ghostkeeper 4 years ago
parent
commit
abffb6c26c
1 changed files with 6 additions and 2 deletions
  1. 6 2
      plugins/3MFReader/ThreeMFWorkspaceReader.py

+ 6 - 2
plugins/3MFReader/ThreeMFWorkspaceReader.py

@@ -738,11 +738,15 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
 
     @staticmethod
     def _loadMetadata(file_name: str) -> Dict[str, Dict[str, Any]]:
-        archive = zipfile.ZipFile(file_name, "r")
+        result = dict()
+        try:
+            archive = zipfile.ZipFile(file_name, "r")
+        except zipfile.BadZipFile:
+            Logger.logException("w", "Unable to retrieve metadata from {fname}: 3MF archive is corrupt.".format(fname = file_name))
+            return result
 
         metadata_files = [name for name in archive.namelist() if name.endswith("plugin_metadata.json")]
 
-        result = dict()
 
         for metadata_file in metadata_files:
             try: