Fix 3mf workspace reader crashing on certain invalid files

CURA-4DP (Sentry crash)
This commit is contained in:
Jaime van Kessel 2022-09-06 14:47:32 +02:00
parent 7d3a617824
commit 2f1325259c
No known key found for this signature in database
GPG key ID: C85F7A3AF1BAA7C4

View file

@ -664,10 +664,22 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
# Create a shadow copy of the preferences (we don't want all of the preferences, but we do want to re-use its
# Create a shadow copy of the preferences (We don't want all of the preferences, but we do want to re-use its
# parsing code.
temp_preferences = Preferences()
try:
serialized = archive.open("Cura/preferences.cfg").read().decode("utf-8")
except KeyError:
# If there is no preferences file, it's not a workspace, so notify user of failure.
Logger.log("w", "File %s is not a valid workspace.", file_name)
message = Message(i18n_catalog.i18nc("@info:error Don't translate the XML tags <filename> or <message>!",
"Project file <filename>{0}</filename> is corrupt: <message>{1}</message>.",
file_name, str(e)),
title=i18n_catalog.i18nc("@info:title", "Can't Open Project File"),
message_type=Message.MessageType.ERROR)
message.show()
self.setWorkspaceName("")
return [], {}
temp_preferences.deserialize(serialized)
# Copy a number of settings from the temp preferences to the global