Tiff file lzw compression bit size needs to be capped at 12#58
Open
dave-price-parsons wants to merge 1 commit intongageoint:masterfrom
Open
Tiff file lzw compression bit size needs to be capped at 12#58dave-price-parsons wants to merge 1 commit intongageoint:masterfrom
dave-price-parsons wants to merge 1 commit intongageoint:masterfrom
Conversation
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.
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.