fix(eps): refuse Illustrator arrays nested past the depth limit

This commit is contained in:
Dylan M. Taylor
2026-11-03 22:16:56 +07:00
committed by bflatastic
parent 4aea3cc95c
commit e3ef19142f
2 changed files with 16 additions and 0 deletions
+8
View File
@@ -82,6 +82,14 @@ impl<'a> Reader<'a> {
// highlight `-- -- angle length Bh`): a NaN keeps the other operands where they are.
"--" => return self.push(V::Num(f64::NAN)),
"[" => {
// Drop marks that operators have taken off, so `marks` is the open nesting.
while self.marks.last().is_some_and(|&m| !matches!(self.stack.get(m), Some(V::Mark))) {
self.marks.pop();
}
// Arrays nest as deep as their `[`s; dropping a deeper one would overflow the stack.
if self.marks.len() >= MAX_DEPTH {
return Err("it has arrays nested too deeply".into());
}
self.marks.push(self.stack.len());
return self.push(V::Mark);
}
+8
View File
@@ -54,6 +54,14 @@ fn ruler_units_from_the_header_set_the_documents_units() {
assert_eq!(read(with_px.as_bytes()).unwrap().doc.units, Unit::Pixels);
}
#[test]
fn arrays_nested_past_the_depth_limit_are_refused() {
let deep = |n: usize| layer(&format!("{}{} pop", "[".repeat(n), "]".repeat(n)));
let nested = |n: usize| read(stream(&deep(n)).as_bytes()).err().is_some_and(|e| e.contains("nested too deeply"));
assert!(!nested(200));
assert!(nested(100_000));
}
/// The children of the first layer.
fn art(doc: &Document) -> Vec<Arc<Node>> {
doc.layers.first().and_then(|l| l.children()).cloned().unwrap_or_default()