Images: read no more than the limit, keep plot bounds to what a viewport shows, free textures with no images left

Review fixes from CodeRabbit on #2749:
- the image file is read through read_capped, so a file that grows after the size check can't exhaust memory
- an image cut by a layout viewport widens the sheet's bounds only by the part inside it, as other primitives do
- uploaded tiles of closed drawings are dropped also when the next list has no images
This commit is contained in:
Tanish Manku
2026-11-03 16:52:11 -07:00
parent bd22363d5e
commit f10e41409d
4 changed files with 38 additions and 17 deletions
+5 -1
View File
@@ -79,7 +79,11 @@ fn read_file(path: &str, host: Option<&str>) -> std::result::Result<Vec<u8>, Str
if len > MAX_IMAGE_BYTES {
return Err(format!("the file is larger than {} MB", MAX_IMAGE_BYTES >> 20));
}
std::fs::read(&file).map_err(|e| e.to_string())
// Read no more than the limit: the file can grow or change after the check above.
let limit = usize::try_from(MAX_IMAGE_BYTES).unwrap_or(usize::MAX);
crate::capped_read::read_capped(&file, limit).map_err(|e| {
if e.kind() == std::io::ErrorKind::InvalidData { format!("the file is larger than {} MB", MAX_IMAGE_BYTES >> 20) } else { e.to_string() }
})
}
#[cfg(target_arch = "wasm32")]
{