Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LZW compression needs a max bit size of 12 #57

Open
dave-price-parsons opened this issue Aug 29, 2024 · 0 comments
Open

LZW compression needs a max bit size of 12 #57

dave-price-parsons opened this issue Aug 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@dave-price-parsons
Copy link

dave-price-parsons commented Aug 29, 2024

Version Information:

  • TIFF Java Version: 3.0.0

Expected Results:

Parse geo tiff images from https://geoint.nrlssc.org/nrltileserver/wcs without an exception
The geotiff can be successfully read with java's ImageIO.read() as well as successfully opened in GIMP.

Observed Results:

Parsing the geotiff would often throw exceptions, sometimes about the byte stream ending early or other problems with the bytes.
The happens on most geotiff downloads from that site

Output:

mil.nga.tiff.util.TiffException: No more remaining bytes to read. Total Bytes: 5707, Byte offset: 5704, Attempted to read: 4
at mil.nga.tiff.io.ByteReader.verifyRemainingBytes(ByteReader.java:415)
at mil.nga.tiff.io.ByteReader.readFloat(ByteReader.java:364)
at mil.nga.tiff.io.ByteReader.readFloat(ByteReader.java:351)
at mil.nga.tiff.FileDirectory.readValue(FileDirectory.java:1353)
at mil.nga.tiff.FileDirectory.readRaster(FileDirectory.java:1294)
at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:1220)
at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:1067)
at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:1019)
at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:998)
at mil.nga.tiff.TiffReadTest.testLzw12BitMax(TiffReadTest.java:396)

Steps to Reproduce:

Download a geotiff from the nrlssc geoint tileserver. Example:
https://geoint.nrlssc.org/nrltileserver/wcs/tlorigin?REQUEST=GetCoverage&VERSION=1.0.0&SERVICE=WCS&COVERAGE=USGS_NED_10m&FORMAT=GeoTIFF&BoundingBox=-117.55,33.41,-117.5,33.46&WIDTH=555&HEIGHT=555

TiffReader.readTiff( file ).getFileDirectory().readRasters();

An exception will probably be thrown about parsing the bytes.

Test Files:

https://geoint.nrlssc.org/nrltileserver/wcs/tlorigin?REQUEST=GetCoverage&VERSION=1.0.0&SERVICE=WCS&COVERAGE=USGS_NED_10m&FORMAT=GeoTIFF&BoundingBox=-117.55,33.41,-117.5,33.46&WIDTH=555&HEIGHT=555

Additional Information:

I have already tracked down the problem and I have a fix in hand including units tests. Comparing this implementation to java's native implementation I see that the number of bits is capped at 12. Adding that to the code allows the successful parsing of the tiff file.

@dave-price-parsons dave-price-parsons added the bug Something isn't working label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant