Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Integration: data merge checks the read roots before the file size

aionggbd99e59e811f
diff --git a/crates/engine/src/cmd/datamerge/mod.rs b/crates/engine/src/cmd/datamerge/mod.rs
index 77c3cee7e..38ec18321 100644
--- a/crates/engine/src/cmd/datamerge/mod.rs
+++ b/crates/engine/src/cmd/datamerge/mod.rs
@@ -779,13 +779,13 @@ fn read_path(path: &str) -> std::result::Result<Vec<u8>, String> {
/// `cap`, so a device or a file that grows while it is read can't exhaust memory.
pub(crate) fn read_path_capped(path: &str, cap: u64) -> std::result::Result<Vec<u8>, String> {
let too_big = || format!("{path}: the file is larger than {} MiB", cap / (1024 * 1024));
+ // The roots' own message when they refuse the path, missing or not.
+ crate::file_access::check_read(path)?;
match crate::io::metadata(path) {
Ok(m) if m.len() > cap => return Err(too_big()),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Err(format!("{path}: the file is missing")),
_ => {}
}
- // The roots' own message when they refuse the path.
- crate::file_access::check_read(path)?;
let b = match crate::io::read_capped(path, cap) {
Ok(b) => b,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Err(format!("{path}: the file is missing")),