Files
craft-libs/crates/exr/src
Dylan M. TayloranddotCooCoo a62de6c7c3 exr: integrate mixed deep/flat decoding with regression coverage (#1853)
* EXR: decode a flat part of a file that also holds deep parts

decode_part refused every part of a file with any deep part, and
decode_display_part, which checked only the selected part, still failed
because the exr crate's image reader validates every header and refuses
deep ones before it reads a chunk.

Both now decide from the selected part's own header. When any part is
deep, the selected flat part is read chunk by chunk: the flat headers are
validated, every part's offset table is walked from the end of the
headers, and only the selected table's chunks are read. A chunk must start
past the last offset table and inside the file, carry the selected part's
number and hold a block no other chunk of the part holds; anything else is
Malformed. Files with only flat parts keep the crate's reader.

The file-size ratio check, which was skipped for every part when any part
was deep, now applies to the flat parts of such a file; deep parts are not
counted.

* EXR: a flat part beside a deep part needs a chunk for each of its blocks

The chunk reader for a flat part of a file that also holds deep parts
refused only a second chunk for the same block. A tiled part's chunk that
named a level the part does not have was skipped without decompressing,
so the tile it took the place of had no chunk and the part decoded with
that tile left at zero.

Each chunk now has to hold one of the part's own blocks, taken from the
header, that no other chunk holds; anything else is Malformed. Since a
part has as many chunks as blocks, every block then has a chunk.

The mixed-file tests also run with a tiled flat part, and a new test
names a missing level and a repeated tile.

* EXR: a scan-line chunk beside a deep part must start at its block's first line

The block index of a scan-line chunk is its y offset divided by the
lines a block holds, rounded toward zero. A chunk whose y was not the
first line of a block, or lay up to 15 lines above the data window of
a ZIP part, still named a block and was decoded into it. Such a chunk
is now Malformed.

* EXR: a block too large to address is LimitExceeded instead of a panic

The exr crate bounds a flat chunk by a block's pixels times the bytes a
pixel takes, an unchecked product, before it reads the chunk. A 1 x 1
part with five float channels in 10^9 x 10^9 tiles passed every size
limit, and decode_part and decode_display_part then panicked with an
overflow, for files of flat parts only and for mixed files alike.
read_meta now computes the product with checked arithmetic for each
flat part and returns LimitExceeded when it does not fit in a usize.

* EXR: a chunk beside a deep part must fit the rest of the file

The exr crate allocates a chunk's declared payload, up to the size of a
block, before it reads it. In a mixed file whose flat part has large
tiles, a chunk declaring i32::MAX bytes made a 2 GiB allocation from a
file of a few hundred bytes. read_flat_part_chunks now reads the
declared length first and returns Malformed when it is longer than the
bytes left in the file.

* test(exr): verify mixed-part ratio and display block budgets

* fix(exr): bound mixed-part payload and block bookkeeping allocations

* fix(exr): expose internal ordinal helpers to regression tests

---------

Co-authored-by: dotCooCoo <RobertLeeLW@gmail.com>
2026-11-16 07:47:06 -05:00
..
2026-11-15 16:11:32 +00:00
2026-11-15 16:23:03 +00:00
2026-11-15 16:16:39 +00:00