diff --git a/crates/io/src/lib.rs b/crates/io/src/lib.rs index 4d1811800..6b2d1c2a3 100644 --- a/crates/io/src/lib.rs +++ b/crates/io/src/lib.rs @@ -825,6 +825,12 @@ pub fn read_design(bytes: &[u8]) -> Result { if is_design_container(bytes) { return design::read(bytes); } + // Every DWG starts with its version (`AC1032`), whatever the file is called (#9328). + if bytes.starts_with(b"AC1") { + return Err(IoError::Invalid( + "this is a DWG file, which SolidCraft can't read: export the model as STEP and open that, or the drawing as DXF and use Insert DXF in a sketch".into(), + )); + } let s = std::str::from_utf8(bytes).map_err(|_| IoError::Invalid("design file is not UTF-8 JSON".into()))?; // Only a file that isn't a design pays for asking whether it is a drawing. Document::from_json(s).map_err(|e| match file_kind(bytes) { @@ -1110,6 +1116,8 @@ mod tests { let back = read_design(&write_design(&doc)).unwrap(); assert_eq!(back, doc); assert!(read_design(b"\xff\xfe").is_err()); + let dwg = read_design(b"AC1032\0\0\0\0\0\xff\xfe").unwrap_err().to_string(); + assert!(dwg.contains("this is a DWG file") && dwg.contains("STEP") && dwg.contains("DXF"), "{dwg}"); assert!(matches!(export(&m.state(), &["nope".into()], Format::Step, "t"), Err(IoError::Empty))); assert_eq!(Format::from_name("a.STP").unwrap(), Format::Step); assert!(is_step_path("/x/Part.STEP") && is_step_path("a.stp") && !is_step_path("a.step.json") && !is_step_path("step"));