From 83a98d43bfa44844ad4dcf3153cbca2854c024f1 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Feb 2024 12:45:52 +0100 Subject: [PATCH 1/2] Fixed crash when loading invalid 3MFs (SPE-2135) The crash was introduced in 040a846, which completely threw away handling of the return value of the importer.load_model_from_file function and replaced it with weaker condition. The purpose of that change was to solve #8401 (missing error message when loading different invalid 3MF). This commit reverts that change (and reintroduces #8401). Handling of 3MF loading errors should be inside the importer.load_model_from_file function, where the check should be added later. --- src/libslic3r/Format/3mf.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index dd9fab6123..d2ca7b1104 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -3574,11 +3574,11 @@ bool load_3mf(const char* path, DynamicPrintConfig& config, ConfigSubstitutionCo // All import should use "C" locales for number formatting. CNumericLocalesSetter locales_setter; _3MF_Importer importer; - importer.load_model_from_file(path, *model, config, config_substitutions, check_version); + bool res = importer.load_model_from_file(path, *model, config, config_substitutions, check_version); importer.log_errors(); handle_legacy_project_loaded(importer.version(), config, importer.prusaslicer_generator_version()); - return !model->objects.empty() || !config.empty(); + return res; } bool store_3mf(const char* path, Model* model, const DynamicPrintConfig* config, bool fullpath_sources, const ThumbnailData* thumbnail_data, bool zip64) From ee8733085926635bf4d9d19cdb8d5b73895b88f3 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 5 Feb 2024 17:17:54 +0100 Subject: [PATCH 2/2] Add check on existing exactly one .model file in 3mf --- src/libslic3r/Format/3mf.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index d2ca7b1104..cd94eeaa07 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -706,12 +706,20 @@ namespace Slic3r { m_name = boost::filesystem::path(filename).stem().string(); // we first loop the entries to read from the archive the .model file only, in order to extract the version from it + bool found_model = false; for (mz_uint i = 0; i < num_entries; ++i) { if (mz_zip_reader_file_stat(&archive, i, &stat)) { std::string name(stat.m_filename); std::replace(name.begin(), name.end(), '\\', '/'); - if (boost::algorithm::istarts_with(name, MODEL_FOLDER) && boost::algorithm::iends_with(name, MODEL_EXTENSION)) { + if (boost::algorithm::iends_with(name, MODEL_EXTENSION)) { + if(found_model){ + close_zip_reader(&archive); + add_error("3mf contain multiple .model files and it is not supported yet."); + return false; + } + found_model = true; + try { // valid model name -> extract model @@ -730,6 +738,11 @@ namespace Slic3r { } } } + if (!found_model) { + close_zip_reader(&archive); + add_error("Not valid 3mf. There is missing .model file."); + return false; + } // we then loop again the entries to read other files stored in the archive for (mz_uint i = 0; i < num_entries; ++i) {