From 616f1e433659581f5e219549f772d2e7306f0bac Mon Sep 17 00:00:00 2001 From: ExPikaPaka Date: Wed, 30 Sep 2026 09:17:43 +0200 Subject: [PATCH] Fix a crash on loading a 3MF with empty project settings opt_float() dereferences what option<>() returns without checking it, and option<>() is called with create = false. Three CLI sites read printable_height that way, so a 3mf whose Metadata/project_settings.config holds an empty object takes the CLI down with a null dereference. Both models shipped in resources/handy_models are such files, so `--info` on either of them segfaults. Guard the three reads the way the neighbouring reads of extruder_clearance_height_to_rod and friends already are. All three target variables are initialised to 0 and the consumer tests for > 0, so an absent setting already had a defined meaning and nothing changes for a project that carries the setting. --- src/OrcaSlicer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 1939988261..afd32da33f 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -1913,7 +1913,10 @@ int CLI::run(int argc, char **argv) old_printable_width = static_cast(old_printable_bbox.size().x()); old_printable_depth = static_cast(old_printable_bbox.size().y()); } - old_printable_height = (int)(config.opt_float("printable_height")); + // A 3mf can carry an empty project_settings.config - the models in + // resources/handy_models do - and opt_float() dereferences without checking. + if (config.option("printable_height")) + old_printable_height = (int)(config.opt_float("printable_height")); if (config.option("extruder_clearance_height_to_rod")) old_height_to_rod = config.opt_float("extruder_clearance_height_to_rod"); @@ -2589,7 +2592,8 @@ int CLI::run(int argc, char **argv) orig_printable_width = static_cast(orig_printable_bbox.size().x()); orig_printable_depth = static_cast(orig_printable_bbox.size().y()); } - orig_printable_height = (int)(config.opt_float("printable_height")); + if (config.option("printable_height")) + orig_printable_height = (int)(config.opt_float("printable_height")); BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(":%1%, check printable size: old_printable_width=%2%, orig_printable_width=%3%, old_printable_depth=%4%, orig_printable_depth=%5%, old_printable_height=%6%, orig_printable_height=%7%") %__LINE__ %old_printable_width %orig_printable_width %old_printable_depth %orig_printable_depth %old_printable_height %orig_printable_height; if ((orig_printable_width > 0) && (orig_printable_depth > 0) && (orig_printable_height > 0)) @@ -4617,7 +4621,8 @@ int CLI::run(int argc, char **argv) BoundingBoxf temp_printable_bbox(temp_printable_area); printer_plate.printable_width = static_cast(temp_printable_bbox.size().x()); printer_plate.printable_depth = static_cast(temp_printable_bbox.size().y()); - printer_plate.printable_height = (int)(config.opt_float("printable_height")); + if (config.option("printable_height")) + printer_plate.printable_height = (int)(config.opt_float("printable_height")); } if (temp_exclude_area.size() >= 4) { printer_plate.exclude_width = (int)(temp_exclude_area[2].x() - temp_exclude_area[0].x());