exr: clamp the scan-line block bound to the part height

A part shorter than its compression's scan-line group (a one-row ZIP16 part) only decodes its
own rows, so the all-channel block bound is min(scan_lines_per_block, layer_h) rows.
This commit is contained in:
FredApps committed 2026-11-16 08:38:50 +01:00
1 parent 15aaced60a
commit 33f35d74f8
2 files changed
+6 -1

No files matched your search

+2 -1
View File
@@ -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)));
+4
View File
@@ -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));