tiff-java
tiff-java copied to clipboard
LZW decompression - Byte offset out of range
Version Information:
- TIFF Java Version: 3.0.0
- TIFF Java Source: mvnrepository
- IDE Name & Version: IntelliJ IDEA
- Maven Version: sbt 1.6.2
- Java Version: openjdk version "11.0.15" 2022-04-19
- Platform & OS: Ubuntu 20.04.4 LTS
Expected Results:
A tiff file that is compressed LZW should be decompressed.
Observed Results:
- When I decompress the tiff with ImageMagick and then run the code, the error does not appear.
- With some OME-TIFFS whether compressed with LZW or uncompressed the problem does not occur.
- With other OME TIFFS (LZW compressed) a similar error appears, e.g.:
End of data reached without an end of input code,No more remaining bytes to read
Output:
[error] mil.nga.tiff.util.TiffException: Byte offset out of range. Total Bytes: 13670, Byte offset: 13670
[error] at mil.nga.tiff.io.ByteReader.setNextByte(ByteReader.java:73)
[error] at mil.nga.tiff.FileDirectory.readRaster(FileDirectory.java:1291)
[error] at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:1220)
[error] at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:1067)
[error] at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:1019)
[error] at mil.nga.tiff.FileDirectory.readRasters(FileDirectory.java:998)
[error] at Main$.delayedEndpoint$Main$1(Main.scala:11)
[error] at Main$delayedInit$body.apply(Main.scala:4)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error] at scala.App.$anonfun$main$1(App.scala:76)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error] at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
[error] at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
[error] at scala.collection.AbstractIterable.foreach(Iterable.scala:926)
[error] at scala.App.main(App.scala:76)
[error] at scala.App.main$(App.scala:74)
[error] at Main$.main(Main.scala:4)
[error] at Main.main(Main.scala)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
Steps to Reproduce:
- Create a SBT project with IntelliJ
- Include
libraryDependencies ++= Seq("mil.nga" % "tiff" % "3.0.0")in build.sbt - Add the relavant code from below in Main
sbt run
Relevant Code:
val input = new File("src/main/resources/test.ome.tif")
val tiffImage = TiffReader.readTiff(input)
val directories = tiffImage.getFileDirectories
val directory = directories.get(0)
val rasters = directory.readRasters