From ca987bf0b5adf1f9acf0db2cd8f4cdcd6821e199 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 6 Jan 2025 14:42:32 +0100 Subject: [PATCH] App: Handle possibly raised exception in ZipFile constructor This fixes the issue reported at: https://forum.freecad.org/viewtopic.php?t=93619 --- src/App/ProjectFile.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/App/ProjectFile.cpp b/src/App/ProjectFile.cpp index 601969e02f..cf56233bc5 100644 --- a/src/App/ProjectFile.cpp +++ b/src/App/ProjectFile.cpp @@ -66,6 +66,26 @@ using namespace App; namespace { + +class ZipTools +{ +public: + static std::unique_ptr open(const std::string& file) + { + std::unique_ptr project; + try { + project = std::make_unique(file); + if (!project->isValid()) { + project.reset(); + } + } + catch (const std::exception&) { + } + + return project; + } +}; + class DocumentMetadata { public: @@ -212,11 +232,12 @@ bool ProjectFile::loadDocument() return true; // already loaded } - zipios::ZipFile project(stdFile); - if (!project.isValid()) { + auto project = ZipTools::open(stdFile); + if (!project) { return false; } - std::unique_ptr str(project.getInputStream("Document.xml")); + + std::unique_ptr str(project->getInputStream("Document.xml")); if (str) { std::unique_ptr parser(new XercesDOMParser); parser->setValidationScheme(XercesDOMParser::Val_Auto);