java-topology/defects/cura-0001/SCAN-NOTES.md

1.8 KiB
Raw Blame History

cura-0001 — CompatibleMachineModel list rebuild O(P²)

Target

Ultimaker Cura (Python/Qt, 3D printing slicer front-end) https://github.com/Ultimaker/Cura

File

cura/Machines/Models/CompatibleMachineModel.py line 55

Defect

for output_device in machine_manager.printerOutputDevices:
    for printer in output_device.printers:
        if printer.name in [item["name"] for item in self.items]:  # O(P) per printer
            continue

Each printer iteration rebuilds a list comprehension [item["name"] for item in self.items] from scratch and scans it linearly. With P printers and I already-added items, the cost is O(P × I). For a print farm with 50 printers this becomes O(50 × 50) = 2500 operations where O(1) amortized is correct.

MOAD

0001 — CWE-407 Algorithmic Complexity, list membership in loop

Severity

LOW-MEDIUM. Triggered on machine manager update events (output device changes, global container changes). In a print farm environment with many printers, every status refresh re-pays this cost.

Fix

Build a set once before the loop:

seen_printer_names = {item["name"] for item in self.items}
for output_device in ...:
    for printer in output_device.printers:
        if printer.name in seen_printer_names:   # O(1)
            continue
        seen_printer_names.add(printer.name)

Speedup

O(P × I) → O(P + I). At P=50 printers, I=50 items: 2500 ops → 100 ops, 25x.

MOADs 0002-0005

  • 0002 Intertangle: CuraApplication.getInstance() god-object is pervasive but pre-existing architectural pattern, not a new defect.
  • 0003 Leaked Context: No threading.local or ThreadLocal found.
  • 0004 Logged Secret: OAuth2 logging only logs URLs and status messages, never actual token values. CLEAN.
  • 0005 Thundering Herd: No unsynchronized cache+null+put pattern found in hot paths. CLEAN.