From 1d9bdb1ca38abef9109b7160be5bc6f8d2d98538 Mon Sep 17 00:00:00 2001 From: raykholo Date: Fri, 23 Oct 2026 14:23:02 +0000 Subject: [PATCH] FreeCAD/Rhino import: decode caps with room for detailed parts (#1783) (#3209) * claim: #1783 * FreeCAD/Rhino import: decode caps with room for detailed parts (#1783) cadmpeg decoded FreeCAD and Rhino files under its service profile, whose million collection items and 2.56e8 work units a detailed part (a sprocket, a threaded rod, a part with a few hundred faces) runs past: the import was refused with "resource limit on CollectionItems: BudgetExceeded". Allow 8 million items and 2e9 work units, half of cadmpeg's desktop profile; the input-size cap stays SolidCraft's STEP limit and every other cap stays at the service profile's. decoding_is_capped checks the two raised caps (and that they stay below the desktop profile's) and that every other cap is still the service one. Fixes #1783 --- crates/io/src/native_cad.rs | 10 +++++++++- crates/io/src/native_cad/tests.rs | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/io/src/native_cad.rs b/crates/io/src/native_cad.rs index 97aa26d50..2e6230a17 100644 --- a/crates/io/src/native_cad.rs +++ b/crates/io/src/native_cad.rs @@ -57,7 +57,15 @@ mod convert { pub(super) fn policy() -> DecodePolicy { DecodePolicy { mode: DecodeMode::Salvage, - limits: ResourceLimits { max_input_bytes: crate::MAX_STEP_BYTES as u64, ..ResourceLimits::service() }, + // Service caps on size, with room for the work a large assembly's decode takes and + // for the collections of a detailed part (a part with thousands of faces holds more + // than the service profile's million items). + limits: ResourceLimits { + max_input_bytes: crate::MAX_STEP_BYTES as u64, + max_work_units: 2_000_000_000, + max_collection_items: 8_000_000, + ..ResourceLimits::service() + }, } } diff --git a/crates/io/src/native_cad/tests.rs b/crates/io/src/native_cad/tests.rs index 28bec0ecf..88011624e 100644 --- a/crates/io/src/native_cad/tests.rs +++ b/crates/io/src/native_cad/tests.rs @@ -100,13 +100,26 @@ fn hostile_native_cad_never_panics() { } } -/// cadmpeg decodes under its tight `service` caps, with our STEP size limit on the input. +/// cadmpeg decodes under its tight `service` caps, with our STEP size limit on the input and +/// room for the work a large assembly takes (2·10⁹ units, half its desktop profile's) and the +/// collections of a detailed part (8·10⁶ items, half its desktop profile's). #[test] fn decoding_is_capped() { let limits = convert::policy().limits; let service = cadmpeg_core::decode::ResourceLimits::service(); + let desktop = cadmpeg_core::decode::ResourceLimits::desktop(); assert_eq!(limits.max_input_bytes, crate::MAX_STEP_BYTES as u64); - assert_eq!(cadmpeg_core::decode::ResourceLimits { max_input_bytes: service.max_input_bytes, ..limits }, service); + assert_eq!(limits.max_work_units, 2_000_000_000); + assert!(limits.max_work_units < desktop.max_work_units); + assert_eq!(limits.max_collection_items, 8_000_000); + assert!(limits.max_collection_items < desktop.max_collection_items); + let same = cadmpeg_core::decode::ResourceLimits { + max_input_bytes: service.max_input_bytes, + max_work_units: service.max_work_units, + max_collection_items: service.max_collection_items, + ..limits + }; + assert_eq!(same, service); } /// A FreeCAD archive whose Document.xml inflates past the per-entry cap (a ZIP bomb, 300 MB of