diff --git a/crates/exr/src/decode.rs b/crates/exr/src/decode.rs index 7daf7a448..d8cb32827 100644 --- a/crates/exr/src/decode.rs +++ b/crates/exr/src/decode.rs @@ -523,7 +523,8 @@ impl<'s> ReadChannels<'s> for DisplaySelect<'_> { // the kept planes and each block fit. let block_pixels = match header.blocks { exr::meta::BlockDescription::Tiles(tiles) => tiles.tile_size.0.min(layer_w).checked_mul(tiles.tile_size.1.min(layer_h)), - exr::meta::BlockDescription::ScanLines => header.compression.scan_lines_per_block().checked_mul(layer_w), + // a part shorter than its compression's scan-line group has only its own rows + exr::meta::BlockDescription::ScanLines => header.compression.scan_lines_per_block().min(layer_h).checked_mul(layer_w), }; let Some(block_bytes) = block_pixels.and_then(|pixels| pixels.checked_mul(header.channels.bytes_per_pixel.max(1))) else { self.block_limit.set(Some(format!("data-window block size exceeds {}", self.limits.max_bytes))); diff --git a/crates/exr/src/decode_tests.rs b/crates/exr/src/decode_tests.rs index e82e42a34..66a64cfb4 100644 --- a/crates/exr/src/decode_tests.rs +++ b/crates/exr/src/decode_tests.rs @@ -144,6 +144,10 @@ fn decoded_display_part_bounds_each_all_channel_block() { let r = |name: &str| name == "R"; assert!(matches!(decode_display_part(&bytes, 0, &r, &|_| 0.0, &Limits { max_bytes: 16, ..Limits::default() }), Err(Error::LimitExceeded(_)))); assert_eq!(decode_display_part(&bytes, 0, &r, &|_| 0.0, &Limits { max_bytes: 64, ..Limits::default() }).unwrap().channels.len(), 1); + // ZIP groups 16 scan lines, but a one-row part's block is that row: still 64 bytes, not 1024 + let zip16 = file(vec![layer(None, 4, 1, &["R", "G", "B", "A"], false, exr::prelude::Compression::ZIP16)], (4, 1)); + assert!(matches!(decode_display_part(&zip16, 0, &r, &|_| 0.0, &Limits { max_bytes: 63, ..Limits::default() }), Err(Error::LimitExceeded(_)))); + assert_eq!(decode_display_part(&zip16, 0, &r, &|_| 0.0, &Limits { max_bytes: 64, ..Limits::default() }).unwrap().channels.len(), 1); // A tile is the block of a tiled part: a 4x4 tile of four f32 channels is 256 bytes, while // the whole 8x8 part is 1024 and the kept R plane of the 2x2 display window only 16. let tiled = file(vec![layer(None, 8, 8, &["R", "G", "B", "A"], true, exr::prelude::Compression::ZIP1)], (2, 2));