CLI: guard 4 null derefs when loading a 3mf without preset ids (#14580)

CLI: guard 4 null derefs when loading a 3mf with no preset ids

At OrcaSlicer.cpp:1700-1704 the post-load block reads printer_settings_id,
print_settings_id, filament_settings_id, and nozzle_diameter from the
config that the 3mf carries. If the 3mf is a BBL/BBS-flavored 3mf but
was produced by a non-GUI writer (e.g. CLI --export-3mf without a
loaded preset) any of those keys can be absent, and config.option<T>(...)
returns nullptr — the ->value / ->values deref then SIGSEGVs.

Wrap each optional lookup in an if-let. printer_model, printer_extruder_variant,
and print_extruder_variant already pass create_if_missing=true and are safe.

Repro (BEFORE this patch):
  orca-slicer --export-3mf out.3mf in.stl   # produces preset-less 3mf
  orca-slicer --info out.3mf                # SIGSEGV at :1700
  bt: __cxx11::basic_string::_M_assign
    -> Slic3r::CLI::run @ OrcaSlicer.cpp:1700

AFTER: --info out.3mf returns exit 0 with the mesh summary.

The same failure mode affected --inspect-mesh, --inspect-paint, and
every other action that has to walk the loaded model's config; --slice
would only survive because it always injects a printer via
--load-settings.
This commit is contained in:
packerlschupfer
2026-07-13 09:10:33 +02:00
committed by GitHub
parent 4eb9a85a49
commit 88262ee504

View File

@@ -1703,11 +1703,13 @@ int CLI::run(int argc, char **argv)
const Vec3d &instance_offset = model_instance->get_offset();
BOOST_LOG_TRIVIAL(info) << boost::format("instance %1% transform {%2%,%3%,%4%} at %5%:%6%")% model_object->name % instance_offset.x() % instance_offset.y() %instance_offset.z() % __FUNCTION__ % __LINE__<< std::endl;
}*/
current_printer_name = config.option<ConfigOptionString>("printer_settings_id")->value;
current_process_name = config.option<ConfigOptionString>("print_settings_id")->value;
// Read defensively — a 3mf missing preset ids (e.g. one produced
// by a non-GUI writer) would otherwise crash here on the deref.
if (const auto *o = config.option<ConfigOptionString>("printer_settings_id")) current_printer_name = o->value;
if (const auto *o = config.option<ConfigOptionString>("print_settings_id")) current_process_name = o->value;
current_printer_model = config.option<ConfigOptionString>("printer_model", true)->value;
current_filaments_name = config.option<ConfigOptionStrings>("filament_settings_id")->values;
current_extruder_count = config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
if (const auto *o = config.option<ConfigOptionStrings>("filament_settings_id")) current_filaments_name = o->values;
if (const auto *o = config.option<ConfigOptionFloats>("nozzle_diameter")) current_extruder_count = o->values.size();
current_printer_variant_count = config.option<ConfigOptionStrings>("printer_extruder_variant", true)->values.size();
current_print_variant_count = config.option<ConfigOptionStrings>("print_extruder_variant", true)->values.size();
current_is_multi_extruder = current_extruder_count > 1;