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

Tiff file lzw compression bit size needs to be capped at 12 #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dave-price-parsons
Copy link

Parsing a geotiff from the nrlssc geoint tileserver 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.

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.

This file can successfully be read using Java's native tiff reading as well as with GIMP.

Comparing this implementation to java's native implementation, I notice the bit size is capped at 12 in java's native implementation. Adding that cap to this code allows the successful parsing of the tiff file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant