From b7cd1ae80dcfa9a8cdb3db1b5feec12045c51907 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 2 Nov 2026 22:55:01 -0800 Subject: [PATCH] Import: match PhotoCraft group depth to the renderer limit --- .../engine/src/interchange/pcraft_import.rs | 12 ++++++--- crates/engine/src/tests/import_photocraft.rs | 25 +++++++++++++++++++ docs/photocraft-import.md | 2 +- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/interchange/pcraft_import.rs b/crates/engine/src/interchange/pcraft_import.rs index 681409f1f..ae3b4e4e0 100644 --- a/crates/engine/src/interchange/pcraft_import.rs +++ b/crates/engine/src/interchange/pcraft_import.rs @@ -8,6 +8,9 @@ use effectcraft_keyframe::Value; use effectcraft_project::{AlphaMode, Comp, Footage, FootageKind, ItemId, ItemKind, LayerSource, Project, SourceLayer, build}; use effectcraft_time::{FrameRate, Tick}; +// Each source group becomes a precomposition; match the renderer's nesting limit. +const MAX_GROUP_DEPTH: usize = 16; + pub(crate) struct Document { outline: Outline, width: u32, @@ -21,10 +24,13 @@ pub(crate) fn read(bytes: &[u8]) -> Result { return Err("PhotoCraft bundle exceeds the 512 MiB input limit".into()); } fn count(layers: &[InputLayer], depth: usize, nodes: &mut usize, pixels: &mut usize) -> Result<(), String> { - if depth > 100 { - return Err("PhotoCraft groups exceed 100 levels".into()); + if depth > MAX_GROUP_DEPTH { + return Err("PhotoCraft groups exceed 16 levels; import as Footage for the saved composite".into()); } for layer in layers { + if depth == MAX_GROUP_DEPTH && layer.kind == "group" { + return Err("PhotoCraft groups exceed 16 levels; import as Footage for the saved composite".into()); + } *nodes += 1; if *nodes > 4096 { return Err("PhotoCraft composition import exceeds 4096 layers; import as Footage for the saved composite".into()); @@ -106,7 +112,7 @@ fn build_comp(project: &mut Project, ctx: &mut Context, name: &str, layers: &[In let mut comp = Comp::new(ctx.doc.width, ctx.doc.height, ctx.rate, ctx.duration); let id = project.add_item(name, Label::Sandstone, parent, ItemKind::Comp(Arc::new(comp.clone()))); ctx.items.push(id); - if depth <= 100 { + if depth <= MAX_GROUP_DEPTH { for input in layers { let index = ctx.next; ctx.next = ctx.next.saturating_add(1); diff --git a/crates/engine/src/tests/import_photocraft.rs b/crates/engine/src/tests/import_photocraft.rs index e9b7af55c..203fc9ecf 100644 --- a/crates/engine/src/tests/import_photocraft.rs +++ b/crates/engine/src/tests/import_photocraft.rs @@ -257,3 +257,28 @@ fn photocraft_layer_buffers_are_bounded_before_decoding_pixels() { assert!(error.contains("1 GiB working-buffer budget") && error.contains("Footage"), "{error}"); std::fs::remove_file(path).unwrap(); } + +#[test] +fn photocraft_group_nesting_stays_within_the_composition_renderer_limit() { + for (depth, blend) in [(16, "Normal"), (16, "PassThrough"), (17, "Normal"), (17, "PassThrough")] { + let mut layers = json!([layer("Deep pixels", true, 1.0, "Normal", json!({"kind":"raster","surface":surface("0000ffff")}))]); + for index in 0..depth { + layers = json!([layer(&format!("Group {index}"), true, 1.0, blend, json!({"kind":"group","children":layers}))]); + } + let path = fixture(&format!("nesting-{depth}-{blend}.pcraft"), layers); + let mut s = Session { footage: std::sync::Arc::new(effectcraft_media::MediaPool::new()), ..Default::default() }; + let before = s.project.items.len(); + let result = s.execute("file.import", json!({"paths":[path],"importAs":"composition"})).unwrap(); + if depth == 16 { + let comp = ItemId(result["comps"][0].as_u64().unwrap()); + assert_eq!(s.render(comp, effectcraft_time::Tick::ZERO, Default::default()).data[0], [0.0, 0.0, 1.0, 1.0]); + } else { + assert_eq!(s.project.items.len(), before, "unsupported nesting must not create a composition with disappearing artwork"); + assert!( + result["errors"].as_array().unwrap().iter().any(|e| e.as_str().is_some_and(|e| e.contains("16 levels") && e.contains("Footage"))), + "{result}" + ); + } + std::fs::remove_file(path).unwrap(); + } +} diff --git a/docs/photocraft-import.md b/docs/photocraft-import.md index 47cdf5a8c..0599fcfbf 100644 --- a/docs/photocraft-import.md +++ b/docs/photocraft-import.md @@ -20,7 +20,7 @@ Use `"importAs":"composition"` for layers. Import uses the existing still-footag ## Limits -PhotoCraft input is limited to 512 MiB. Whole-file ZIP reads share that limit, checked from the archive signature before allocating the input, so renaming a bundle does not bypass it. Decoded composites are limited to 16,777,216 pixels and layer canvases to 12,582,912 pixels. Composition import also respects EffectCraft's composition size limit, allows up to 4,096 layers and 100 levels of group nesting, and rejects unsupported CMYK or Lab layer data. Footage can still import a supported saved composite when the document's layers exceed those limits. +PhotoCraft input is limited to 512 MiB. Whole-file ZIP reads share that limit, checked from the archive signature before allocating the input, so renaming a bundle does not bypass it. Decoded composites are limited to 16,777,216 pixels and layer canvases to 12,582,912 pixels. Composition import also respects EffectCraft's composition size limit, allows up to 4,096 layers and 16 levels of group nesting, and rejects unsupported CMYK or Lab layer data. Footage can still import a supported saved composite when the document's layers exceed those limits. Unsupported layer kinds are skipped with a message naming the layer. A nonempty document with no supported pixel layers cannot import as a composition; the error recommends Footage. Invalid input reports an error before adding a composition.