DXF: read every ENTITIES section, not only the last (fixes #865) (#869)

This commit is contained in:
Marco Arnulfo authored and GitHub committed 2026-10-13 04:38:24 -04:00
1 parent 2effc8bf3e
commit 50246683c3
2 files changed
+21 -1

No files matched your search

+2 -1
View File
@@ -1603,7 +1603,8 @@ pub fn read(bytes: &[u8]) -> Result<Drawing> {
}
}
}
"ENTITIES" => entities = parse_entities(&records(&s.tags), &mut d, &mut rx),
// A damaged file may split its entities over several ENTITIES sections (#865).
"ENTITIES" => entities.extend(parse_entities(&records(&s.tags), &mut d, &mut rx)),
"OBJECTS" => {
for (k, tg) in records(&s.tags) {
objs.add(&k, &tg);
+19
View File
@@ -0,0 +1,19 @@
//! A damaged DXF can split its entities over several ENTITIES sections (with stray header
//! variables and ENDSECs between them, and no EOF). Every section is read, not just the last
//! one (#865).
use cadcraft_doc::EntityKind;
#[test]
fn entities_of_every_entities_section_are_read() {
let text = "0\nSECTION\n2\nENTITIES\n\
0\nTEXT\n8\n0\n10\n0\n20\n0\n40\n1\n1\nA\n\
0\nLINE\n8\n0\n10\n0\n20\n0\n11\n1\n21\n0\n\
0\nENDSEC\n9\n$EXTMIN\n10\n0\n20\n0\n0\nENDSEC\n\
0\nSECTION\n2\nENTITIES\n0\nLINE\n8\n0\n10\n0\n20\n1\n11\n1\n21\n1\n0\nENDSEC\n\
0\nSECTION\n2\nENTITIES\n0\nENDSEC\n";
let d = cadcraft_io::read(text.as_bytes(), "t.dxf").unwrap();
let lines = d.model.iter().filter(|e| matches!(e.kind, EntityKind::Line(_))).count();
let texts = d.model.iter().filter(|e| matches!(e.kind, EntityKind::Text(_))).count();
assert_eq!((lines, texts, d.model.len()), (2, 1, 3));
}