jiayuasu opened a new pull request, #3259:
URL: https://github.com/apache/sedona/pull/3259

   ## Did you read the Contributor Guide?
   
   - Yes, I have read the [Contributor 
Rules](https://sedona.apache.org/latest/community/rule/) and [Contributor 
Development Guide](https://sedona.apache.org/latest/community/develop/)
   
   ## Is this PR related to a ticket?
   
   - Yes, and the PR name follows the format `[GH-XXX] my subject`. Closes #3245
   
   ## What changes were proposed in this PR?
   
   `RS_AsCOG` threw `ArrayIndexOutOfBoundsException` at `Deflater.setInput` for 
1024x1024 byte-band rasters. The root cause is in imageio-ext's `TIFFDeflater`: 
it passes `(offset, height * scanlineStride)` verbatim to 
`Deflater.setInput()`. The COG pipeline's overview images are JAI 
`PlanarImage`s 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:
   
   - When it did not crash, it compressed the inter-row slack between tile 
width and scanline stride, silently corrupting overview pixels for non-empty 
data.
   - The full-resolution write crashes the same way for any byte raster whose 
image is tiled wider than the output tile size (e.g. loaded from a 512-tiled 
GeoTIFF).
   
   The fix retiles byte-band coverages to the output tile grid in `CogWriter` 
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, 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 with `overviewCount=0`, covering the 
full-resolution-path variant.
   
   Full `common` module suite passes (1288 tests).
   
   ## Did this PR include necessary documentation updates?
   
   - No, this PR does not affect any public API so no need to change the 
documentation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to