Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

FreeCAD/Rhino import: decode caps with room for detailed parts (#1783) (#3209)

raykholo1d9bdb1ca38a
diff --git a/crates/io/src/native_cad.rs b/crates/io/src/native_cad.rs
index 97aa26d505..2e6230a17d 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 28bec0ecf5..88011624ea 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