Repository navigation
GeoTIFF: read tiled files with bands stored apart without panicking - #549
Conversation
The tiff crate works out a tile's padding from its index without wrapping it to the band plane, so in a tiled image whose bands are stored apart (GDAL's INTERLEAVE=BAND) every band after the first has its bottom tiles treated as unpadded. Read whole, the decoder asserts on the short buffer and panics; read a tile at a time (large files, and overviews made as the file is read), those tiles come back at full height and their rows were placed skewed, garbling the bottom strip of every band but the first. Such images are now always read a tile at a time, and a chunk's row length is taken from the shape its decoded length matches rather than from the image rows alone. Fixes #544
Code reviewI reviewed the single changed file, Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared: the whole PR against main (merge base 6a17430 to PR head 032e9cb).
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
The decoder reads tiled images with bands stored apart whole when no bottom tile is padded, so only padded ones, read in full, are refused below 8 bits a sample. Names the shape tie-break in Chunks::place.
Code reviewThe PR fixes #544 by reading tiled GeoTIFFs with separately stored bands (planar configuration 2) one tile at a time, instead of whole. I found no crash or correctness bug. I raised two low-confidence concerns as inline comments. I only read the diff and the surrounding code, and did not build or run the tests. Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared: the whole PR against main (merge base 6a17430 to PR head 084ab70)
|
Root cause
The
tiffcrate (0.11.3) works out a tile's padding from its index asrow = tile / tiles_acrosswithout wrapping the index to its band plane. In a tiled GeoTIFF whose bands are stored apart (INTERLEAVE=BAND, PlanarConfiguration 2), every band after the first therefore has its bottom row of tiles treated as unpadded:read_image_to_buffer, used for images under a million pixels, from bytes in memory and in the browser), the decoder asserts on the buffer it sliced for those tiles and panics (image.rs:919), which is the crash in the issue.read_chunkreturns those tiles at full tile height, andChunks::placeinferred the row length from the decoded length divided by the image rows, so the bottom strip of bands 2 and 3 came out skewed (a red band with noisy rows along the bottom of the Landsat image).The first half of the issue (reading planar COGs in place by range) already works on
mainsince #542:layer.addUrlonlandsat_ts/1984.tifopens in place and renders correctly.Fix
read_limitedreads tiled multi-band planar images a tile at a time (decimatewith k = 1) instead of throughread_image_to_buffer; tiled planar images under 8 bits a sample, which can't be read so, keep the whole read when no bottom tile is padded (the decoder handles those) and otherwise return an error instead of reaching the decoder.Chunks::placetakes a chunk's row length from whichever shape (data or tile width, by image or tile rows) its decoded length matches, preferring the data width and rows.Test
tiled_bands_stored_apart_are_read_wholebuilds planar tiled RGB TIFFs with padded right, bottom and corner tiles, and checks every pixel of every band read whole and with every 2nd pixel. Without the routing it panics in thetiffcrate; without the stride fix it fails on band 1's bottom tiles.Verification
landsat_ts/1984.tif) read throughgeotiff::readfrom memory: panicked before, reads 2088 × 1143 × 3 now.layer.addDataand exported: the bottom strip garbled onmain, clean on this branch.layer.addUrl: in place, as onmain.cargo xtask ciand the wasm32 build ofrustgis-webpass locally (one unrelated engine streaming test flaked once under load and passes on rerun).Fixes #544
Summary by CodeRabbit