Bound Out-of-Range filament_map and physical_extruder_map Values (#17476)

* Treat a filament_map Nozzle Outside the Printer as Nozzle 1

A filament_map entry of 0, a negative number or a number above the
nozzle count made Extruder::extruder_id() wrap or run past the end, and
print_machine_envelope then took the std::max over the per-extruder
machine limits out of bounds on a flavour that emits them.

Print::apply now treats an entry outside [1, nozzle count] as nozzle 1,
before the variant expansion and the config snapshot, and logs it once.
After the clamp the slicing engine only sees in-range values. It works
on this print's copy of the config; readers of the plate or project
config are not changed, and in-range maps are left alone.

* Skip a physical_extruder_map Entry Outside the Per-Nozzle Table on Export

The first-filament table built for the start G-code is sized by the
nozzle count, and the export wrote it at the index named by
physical_extruder_map. An entry outside that range corrupted the heap,
and a negative one aborted or hung the export.

The value is a firmware tool number that is also emitted elsewhere, so
it is left as it is; only the write into the table is bounded.

* Treat a filament_map Nozzle Outside the Printer as Nozzle 1 in the CLI

With --filament-map-mode Manual on a multi-nozzle profile, the CLI
indexed the per-nozzle unprintable-filament sets, and shifted the
per-filament printable status, with the raw filament_map value. A value
of 0, a negative number or one above the nozzle count read out of bounds
and crashed before the print was configured.

The checks now use a local copy of the map in which an entry outside
[1, nozzle count] is nozzle 1, the same policy Print::apply applies.
In-range maps are unchanged.
This commit is contained in:
HanifKoh authored and GitHub committed 2026-11-18 14:04:32 +08:00
1 parent 8ebb0a9a2b
commit d3992c2288
4 files changed
+116 -1

No files matched your search

+4 -1
View File
@@ -3731,7 +3731,10 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
std::vector<int> physicial_first_filaments;
physicial_first_filaments.resize(filaments.size());
for (int extruder_id = 0; extruder_id < filaments.size(); extruder_id++) {
physicial_first_filaments[config.physical_extruder_map.get_at(extruder_id)] = filaments[extruder_id];
// The map value is a firmware tool number, so it may legitimately fall outside this table.
const int physical_id = config.physical_extruder_map.get_at(extruder_id);
if (physical_id >= 0 && physical_id < static_cast<int>(physicial_first_filaments.size()))
physicial_first_filaments[physical_id] = filaments[extruder_id];
}
filaments = physicial_first_filaments;
};