Skip to content

Commit

Permalink
App: Handle possibly raised exception in ZipFile constructor
Browse files Browse the repository at this point in the history
This fixes the issue reported at: https://forum.freecad.org/viewtopic.php?t=93619
  • Loading branch information
wwmayer committed Jan 6, 2025
1 parent 26536c9 commit 973de0b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/App/ProjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ using namespace App;

namespace
{

class ZipTools
{
public:
static std::unique_ptr<zipios::ZipFile> open(const std::string& file)
{
std::unique_ptr<zipios::ZipFile> project;
try {
project = std::make_unique<zipios::ZipFile>(file);
if (!project->isValid()) {
project.reset();
}
}
catch (const std::exception&) {
}

return project;
}
};

class DocumentMetadata
{
public:
Expand Down Expand Up @@ -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<std::istream> str(project.getInputStream("Document.xml"));

std::unique_ptr<std::istream> str(project->getInputStream("Document.xml"));
if (str) {
std::unique_ptr<XercesDOMParser> parser(new XercesDOMParser);
parser->setValidationScheme(XercesDOMParser::Val_Auto);
Expand Down

0 comments on commit 973de0b

Please sign in to comment.