From e8aadde3854226730059d1294e91c316609eeb83 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 16 Oct 2026 04:21:30 +0000 Subject: [PATCH] Integration: start-screen previews read only the zip directory and the preview entry --- crates/engine/src/cmd/file.rs | 4 ++-- crates/engine/src/io.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index 26ae6dcff..3a43b164d 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -409,8 +409,8 @@ pub struct RecentPreview { pub fn recent_preview(path: &str) -> Option { #[cfg(not(target_arch = "wasm32"))] { - let bytes = crate::io::read(path).ok()?; - let png = designcraft_format::read_preview(std::io::Cursor::new(bytes))?; + // Only the zip directory and the preview entry are read, not the whole document. + let png = designcraft_format::read_preview(std::io::BufReader::new(crate::io::open(path).ok()?))?; let img = designcraft_images::decode_rgba(&png)?; let (width, height) = img.dimensions(); Some(RecentPreview { width, height, rgba: img.into_raw() }) diff --git a/crates/engine/src/io.rs b/crates/engine/src/io.rs index b27878a63..9eb8850ad 100644 --- a/crates/engine/src/io.rs +++ b/crates/engine/src/io.rs @@ -37,6 +37,15 @@ pub fn read_capped(path: impl AsRef, cap: u64) -> std::io::Result> Ok(b) } +/// The file at `path` opened for reading, inside the automation read root when there is one, for +/// callers that read only part of it. A refused path is a `PermissionDenied` error carrying the +/// roots' message. +pub fn open(path: impl AsRef) -> std::io::Result { + let path = path.as_ref(); + crate::file_access::check_read(path).map_err(|e| std::io::Error::new(std::io::ErrorKind::PermissionDenied, e))?; + std::fs::File::open(path) +} + /// The text of the file at `path`, inside the automation read root when there is one. pub fn read_to_string(path: impl AsRef) -> Result { let path = path.as_ref();