diff --git a/crates/engine/src/cmd/fileio/psdlayers.rs b/crates/engine/src/cmd/fileio/psdlayers.rs index 75aadb1c01..67958a550b 100644 --- a/crates/engine/src/cmd/fileio/psdlayers.rs +++ b/crates/engine/src/cmd/fileio/psdlayers.rs @@ -1156,13 +1156,14 @@ impl [f32; 3]> Builder<'_, F> { let bytes = (row as u64).saturating_mul(rows as u64); if bytes > self.room() { return Ok(false); - } else { - self.spend(bytes)?; - match layer_channel(data, rows, row, self.h.psb, depth) { - Ok(plane) => (0..rows) - .all(|y| plane.get(y * row..(y + 1) * row).is_some_and(|r| (0..w).all(|x| byte(sample(r, x, depth, false)) == 0))), - Err(_) => false, + } + // Not counted against the import's allowance: the transparency is read again, and + // counted, where the layer is drawn. + match layer_channel(data, rows, row, self.h.psb, depth) { + Ok(plane) => { + (0..rows).all(|y| plane.get(y * row..(y + 1) * row).is_some_and(|r| (0..w).all(|x| byte(sample(r, x, depth, false)) == 0))) } + Err(_) => false, } } _ => false, diff --git a/crates/engine/src/cmd/fileio/tests_psdlayers.rs b/crates/engine/src/cmd/fileio/tests_psdlayers.rs index 46a8f5eb9f..09acabbfa0 100644 --- a/crates/engine/src/cmd/fileio/tests_psdlayers.rs +++ b/crates/engine/src/cmd/fileio/tests_psdlayers.rs @@ -2247,6 +2247,12 @@ fn damaged_layers_never_panic() { assert!(psdlayers::import(&file(8, 8, &many[..16], 8, false, false), false, 512, cms).unwrap().is_some()); let e = psdlayers::import(&file(8, 8, &many, 8, false, false), false, 512, cms).err(); assert!(e.as_deref().is_some_and(|e| e.contains("take more memory to read than allowed")), "{e:?}"); + // Looking through those layers' transparency for pixels that draw, below an adjustment layer, + // takes nothing from the allowance. + let mut clear: Vec = (0..16).map(|_| layer("x", [0, 0, 8, 8], [1, 2, 3, 0])).collect(); + clear.push(adjustment("Invert", b"nvrt", &[])); + let opened = psdlayers::import(&file(8, 8, &clear, 8, false, false), false, 512, cms); + assert!(opened.as_ref().is_ok_and(Option::is_some), "{:?}", opened.err()); } /// A layer in a mode VectorCraft lacks above a pass-through group merges with the group's layers