From bf162c2215e84f7f96f4894bc7fa2008c45ef4d8 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 11 Nov 2026 16:23:30 -0500 Subject: [PATCH] automation: save_bytes never reads linked files (#11233) --- crates/automation/src/files.rs | 4 ++- .../automation/tests/it/linked_save_bytes.rs | 29 +++++++++++++++++++ crates/automation/tests/it/main.rs | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 crates/automation/tests/it/linked_save_bytes.rs diff --git a/crates/automation/src/files.rs b/crates/automation/src/files.rs index a9ef67274d..1913566f4a 100644 --- a/crates/automation/src/files.rs +++ b/crates/automation/src/files.rs @@ -203,7 +203,9 @@ pub fn save_bytes_with_renderer( } return Ok((bytes, warnings)); } - let result = photocraft_io::export_with_renderer(doc, &ext, opts, &photocraft_raster::Interrupt::NONE, renderer)?; + // No ambient authority: a linked path inside the document must not be read and embedded. + let opts = ExportOptions { read_linked_files: false, ..opts.clone() }; + let result = photocraft_io::export_with_renderer(doc, &ext, &opts, &photocraft_raster::Interrupt::NONE, renderer)?; Ok((result.bytes, result.warnings)) } diff --git a/crates/automation/tests/it/linked_save_bytes.rs b/crates/automation/tests/it/linked_save_bytes.rs new file mode 100644 index 0000000000..42ecd8b89a --- /dev/null +++ b/crates/automation/tests/it/linked_save_bytes.rs @@ -0,0 +1,29 @@ +//! `files::save_bytes` is the capability-scoped encoder: a linked path inside the document must +//! not be read through ambient filesystem authority and embedded in the returned bytes. + +use photocraft_automation::files; +use photocraft_doc::{Document, Layer, LayerContent, SmartContentsId, SmartObject, SmartSource}; + +#[test] +fn a_linked_smart_object_is_not_read_into_the_bytes() { + let mut doc = Document::new("linked", photocraft_doc::Size::new(8, 6), photocraft_doc::ColorMode::Rgb, photocraft_doc::SampleType::U8); + let linked = std::env::current_exe().unwrap(); + let smart = SmartObject { + contents_id: SmartContentsId::fresh(), + source: SmartSource::Linked { path: linked.to_string_lossy().into_owned() }, + transform: photocraft_geom::Affine::IDENTITY, + smart_filters: vec![], + cache: Some(photocraft_raster::Surface::new(doc.pixel_format())), + psd_raw: None, + filters_enabled: true, + filter_mask: None, + warp: None, + stack_mode: None, + perspective: None, + vector_preview: None, + }; + doc.layers.push(Layer::new("Linked", LayerContent::Smart(smart))); + let (bytes, warnings) = files::save_bytes(&doc, "out.psd", None, &Default::default()).unwrap(); + assert!(warnings.iter().any(|w| w.contains("not read for this export")), "{warnings:?}"); + assert!(bytes.len() < 1 << 20, "the test executable was not embedded"); +} diff --git a/crates/automation/tests/it/main.rs b/crates/automation/tests/it/main.rs index ed98e61b6b..9a551dd087 100644 --- a/crates/automation/tests/it/main.rs +++ b/crates/automation/tests/it/main.rs @@ -9,6 +9,7 @@ mod gpu_backend; mod inactive_save; mod krita; mod layered_save_dirty; +mod linked_save_bytes; mod mcp; mod mcp_wire; mod missing_font_warnings;