DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Integration: start-screen previews read only the zip directory and the preview entry
aiongge8aadde38542
diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rsindex 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<RecentPreview> {#[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.rsindex 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<Path>, cap: u64) -> std::io::Result<Vec<u8>>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<Path>) -> std::io::Result<std::fs::File> {+ 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<Path>) -> Result<String, String> {let path = path.as_ref();