mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-26 19:26:46 -06:00
Integration: data merge checks the read roots before the file size
This commit is contained in:
@@ -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")),
|
||||
|
||||
Reference in New Issue
Block a user