Reject compression='jpeg' in to_geotiff (no JPEGTables)#1514
Merged
brendancol merged 1 commit intoxarray-contrib:mainfrom May 8, 2026
Merged
Reject compression='jpeg' in to_geotiff (no JPEGTables)#1514brendancol merged 1 commit intoxarray-contrib:mainfrom
brendancol merged 1 commit intoxarray-contrib:mainfrom
Conversation
The JPEG-in-TIFF write path tags compression=7 (new-style JPEG) but writes a self-contained JFIF stream per tile/strip and never emits the JPEGTables tag (347) that the TIFF spec requires for that codec. libtiff, GDAL, and rasterio all reject the file with "TIFFReadEncodedStrip() failed". The internal reader round-trips because Pillow decodes the standalone JFIF bytes directly, which hides the break from xrspatial's own tests. Fix: reject compression='jpeg' at the to_geotiff entry point with a ValueError that points at deflate/zstd/lzw. The lower-level _writer.write is untouched so the existing self-decoding tests still demonstrate the codec works internally; re-enabling the public path needs a JPEGTables-aware encoder.
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.
Summary
Pass-8 accuracy sweep finding. The JPEG-in-TIFF write path tags compression=7 (new-style JPEG) but writes a self-contained JFIF stream per tile/strip and never emits the JPEGTables tag (347) that the TIFF spec requires for that codec. libtiff, GDAL, and rasterio all reject the file with
TIFFReadEncodedStrip() failed. Our reader round-trips because Pillow decodes the standalone JFIF bytes directly, which masks the break. The user thinks they wrote a TIFF; nothing else can read it.Repro:
```python
import numpy as np, xarray as xr, rasterio
from xrspatial.geotiff import to_geotiff
arr = np.zeros((32, 32, 3), dtype=np.uint8); arr[..., 0] = 200
da = xr.DataArray(
arr, dims=['y','x','band'],
coords={'y': np.arange(32), 'x': np.arange(32), 'band': [0,1,2]},
attrs={'crs': 4326},
)
to_geotiff(da, '/tmp/x.tif', compression='jpeg', tiled=False)
rasterio.open('/tmp/x.tif').read() # CPLE_AppDefinedError: TIFFReadEncodedStrip() failed
```
Fix: reject
compression='jpeg'at theto_geotiffentry point with a clear ValueError pointing at deflate/zstd/lzw. The lower-level_writer.writeis untouched so the existing self-decoding tests still cover the codec until someone wires up a JPEGTables-aware encoder.Test plan
test_to_geotiff_jpeg_rejectedcovers the user-facing error_writer.writeJPEG round-trip tests pass unchanged