[GH-3245] Fix RS_AsCOG ArrayIndexOutOfBoundsException for byte-band rasters - #3259
Open
jiayuasu wants to merge 1 commit into
Open
[GH-3245] Fix RS_AsCOG ArrayIndexOutOfBoundsException for byte-band rasters#3259jiayuasu wants to merge 1 commit into
jiayuasu wants to merge 1 commit into
Conversation
…band rasters imageio-ext's TIFFDeflater passes (offset, height * scanlineStride) verbatim to Deflater.setInput(). When TIFFImageWriter's 8-bit optimized path hands it a raster sharing a source tile wider than the output tile (e.g. a JAI overview image with a single 512x512 tile written as 256x256 tiles), the range overruns the backing array on the last row of tiles. The same path also compressed the inter-row slack of wide source tiles, corrupting overview pixels. The bug is still present in imageio-ext 2.1.0. Work around it in CogWriter by retiling byte-band coverages to the output tile grid before handing them to GeoTiffWriter, so every raster the writer reads starts at offset 0 of a tile-sized buffer. The copy happens lazily one tile at a time via javax.media.jai.TiledImage; pixel data and the written TIFF are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes RS_AsCOG throws ArrayIndexOutOfBoundsException for 1024x1024 byte-band rasters #3245What changes were proposed in this PR?
RS_AsCOGthrewArrayIndexOutOfBoundsExceptionatDeflater.setInputfor 1024x1024 byte-band rasters. The root cause is in imageio-ext'sTIFFDeflater: it passes(offset, height * scanlineStride)verbatim toDeflater.setInput(). The COG pipeline's overview images are JAIPlanarImages tiled wider than the 256px output tile (a 1024 input produces a single-tile 512x512 overview);TIFFImageWriter's 8-bit optimized path hands the compressor the overview's backing array with a tile offset and the full scanline stride, and for the last row of output tiles the computed range overruns the array. Only byte bands take that direct-buffer path, which is why int/double rasters were unaffected. The bug is still present in imageio-ext 2.1.0.Two related consequences of the same code path are also covered:
The fix retiles byte-band coverages to the output tile grid in
CogWriterbefore handing them toGeoTiffWriter, so every raster the writer reads starts at offset 0 of a tile-sized buffer. The copy happens lazily one tile at a time viajavax.media.jai.TiledImage; pixel data, geo-referencing, sample dimensions, and metadata are unchanged, and non-byte bands are untouched.How was this patch tested?
New regression tests in
CogWriterTest:testWriteByteBandRasterAsCog: byte rasters at 512/768/1024/1536 write successfully and full-resolution pixel values round-trip exactly (the 1024 and 1536 cases crashed before this fix).testByteBandOverviewPixelsSurviveCogEncoding: reads the overview IFD back and verifies overview pixel content, catching the silent stride corruption.testWriteTiledByteSourceAsCog: a byte coverage whose own image is 512-tiled writes correctly withoverviewCount=0, covering the full-resolution-path variant.Full
commonmodule suite passes (1288 tests).Did this PR include necessary documentation updates?