From d8dedc86fc277dde3b488b6e30ac74a125e0a44d Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Fri, 2 Jan 2015 17:45:56 +0100 Subject: [PATCH] TMI-89: Fix exception in LZWDecoder for TIFF with LZW strings longer than strip/tile width --- .../twelvemonkeys/imageio/plugins/tiff/TIFFImageReader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReader.java b/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReader.java index a2715793..86b9105e 100755 --- a/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReader.java +++ b/imageio/imageio-tiff/src/main/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReader.java @@ -665,7 +665,7 @@ public class TIFFImageReader extends ImageReaderBase { ? IIOUtil.createStreamAdapter(imageInput, stripTileByteCounts[i]) : IIOUtil.createStreamAdapter(imageInput); - adapter = createDecompressorStream(compression, stripTileWidth, adapter); + adapter = createDecompressorStream(compression, stripTileWidth, numBands, adapter); adapter = createUnpredictorStream(predictor, stripTileWidth, numBands, getBitsPerSample(), adapter, imageInput.getByteOrder()); if (interpretation == TIFFExtension.PHOTOMETRIC_YCBCR && rowRaster.getTransferType() == DataBuffer.TYPE_BYTE) { @@ -1263,14 +1263,14 @@ public class TIFFImageReader extends ImageReaderBase { } } - private InputStream createDecompressorStream(final int compression, final int width, final InputStream stream) throws IOException { + private InputStream createDecompressorStream(final int compression, final int width, final int bands, final InputStream stream) throws IOException { switch (compression) { case TIFFBaseline.COMPRESSION_NONE: return stream; case TIFFBaseline.COMPRESSION_PACKBITS: return new DecoderStream(stream, new PackBitsDecoder(), 1024); case TIFFExtension.COMPRESSION_LZW: - return new DecoderStream(stream, LZWDecoder.create(LZWDecoder.isOldBitReversedStream(stream)), width); + return new DecoderStream(stream, LZWDecoder.create(LZWDecoder.isOldBitReversedStream(stream)), width * bands); case TIFFExtension.COMPRESSION_ZLIB: // TIFFphotoshop.pdf (aka TIFF specification, supplement 2) says ZLIB (8) and DEFLATE (32946) algorithms are identical case TIFFExtension.COMPRESSION_DEFLATE: