From 3d11c5fc520fba0a67ae5d81544fe7288c167966 Mon Sep 17 00:00:00 2001 From: Sven Lafebre Date: Mon, 16 Nov 2026 08:18:34 +0100 Subject: [PATCH] Palette PNG indices: the memory check counts whole tiles and the row buffer --- crates/io/src/flat.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/io/src/flat.rs b/crates/io/src/flat.rs index cff18fb53ab..e4521f32882 100644 --- a/crates/io/src/flat.rs +++ b/crates/io/src/flat.rs @@ -294,7 +294,8 @@ fn png_color_indices(bytes: &[u8], doc: &Document) -> Option { let width = usize::try_from(w).ok()?; let rows = usize::try_from(TILE_SIZE).ok()?; let band_len = width.checked_mul(rows)?; - let needed = u64::from(w).checked_mul(u64::from(h))?.checked_add(u64::try_from(band_len).ok()?)?; + // The index surface's whole tiles, the band, and the row of the layer read beside it. + let needed = tile_bytes(w, h, 1).saturating_add(u64::from(w).saturating_mul(rows as u64 + 4)); crate::memory::check_fits(w, h, needed, crate::memory::available()).ok()?; let mut band = Vec::new(); band.try_reserve_exact(band_len).ok()?;