commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1764288 - in /commons/proper/imaging/trunk/src: changes/changes.xml main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
Date Tue, 11 Oct 2016 16:22:31 GMT
Author: sebb
Date: Tue Oct 11 16:22:31 2016
New Revision: 1764288

URL: http://svn.apache.org/viewvc?rev=1764288&view=rev
Log:
IMAGING-190 ImageDataReader.decompress() overwrites its input

Modified:
    commons/proper/imaging/trunk/src/changes/changes.xml
    commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java

Modified: commons/proper/imaging/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1764288&r1=1764287&r2=1764288&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/changes/changes.xml (original)
+++ commons/proper/imaging/trunk/src/changes/changes.xml Tue Oct 11 16:22:31 2016
@@ -46,6 +46,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="1.0" date="TBA" description="First major release">
+      <action issue="IMAGING-190" dev="sebb" type="fix">
+        ImageDataReader.decompress() overwrites its input
+      </action>
       <action issue="IMAGING-193" dev="sebb" type="fix">
         Duplicate class names
       </action>

Modified: commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java?rev=1764288&r1=1764287&r2=1764288&view=diff
==============================================================================
--- commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
(original)
+++ commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
Tue Oct 11 16:22:31 2016
@@ -137,7 +137,7 @@ public abstract class ImageDataReader {
         return samples;
     }
 
-    protected byte[] decompress(final byte[] compressed, final int compression,
+    protected byte[] decompress(final byte[] compressedInput, final int compression,
             final int expectedSize, final int tileWidth, final int tileHeight)
             throws ImageReadException, IOException {
         final TiffField fillOrderField = directory.findField(TiffTagConstants.TIFF_TAG_FILL_ORDER);
@@ -145,11 +145,14 @@ public abstract class ImageDataReader {
         if (fillOrderField != null) {
             fillOrder = fillOrderField.getIntValue();
         }
+        final byte[] compressedOrdered; // re-ordered bytes (if necessary)
         if (fillOrder == TiffTagConstants.FILL_ORDER_VALUE_NORMAL) {
+            compressedOrdered = compressedInput;
             // good
         } else if (fillOrder == TiffTagConstants.FILL_ORDER_VALUE_REVERSED) {
-            for (int i = 0; i < compressed.length; i++) {
-                compressed[i] = (byte) (Integer.reverse(0xff & compressed[i]) >>>
24);
+            compressedOrdered = new byte[compressedInput.length];
+            for (int i = 0; i < compressedInput.length; i++) {
+                compressedOrdered[i] = (byte) (Integer.reverse(0xff & compressedInput[i])
>>> 24);
             }
         } else {
             throw new ImageReadException("TIFF FillOrder=" + fillOrder
@@ -158,10 +161,10 @@ public abstract class ImageDataReader {
 
         switch (compression) {
         case TIFF_COMPRESSION_UNCOMPRESSED: // None;
-            return compressed;
+            return compressedOrdered;
         case TIFF_COMPRESSION_CCITT_1D: // CCITT Group 3 1-Dimensional Modified
                                         // Huffman run-length encoding.
-            return T4AndT6Compression.decompressModifiedHuffman(compressed,
+            return T4AndT6Compression.decompressModifiedHuffman(compressedOrdered,
                     tileWidth, tileHeight);
         case TIFF_COMPRESSION_CCITT_GROUP_3: {
             int t4Options = 0;
@@ -177,10 +180,10 @@ public abstract class ImageDataReader {
             }
             final boolean hasFillBitsBeforeEOL = (t4Options & TIFF_FLAG_T4_OPTIONS_FILL)
!= 0;
             if (is2D) {
-                return T4AndT6Compression.decompressT4_2D(compressed,
+                return T4AndT6Compression.decompressT4_2D(compressedOrdered,
                         tileWidth, tileHeight, hasFillBitsBeforeEOL);
             }
-            return T4AndT6Compression.decompressT4_1D(compressed,
+            return T4AndT6Compression.decompressT4_1D(compressedOrdered,
                     tileWidth, tileHeight, hasFillBitsBeforeEOL);
         }
         case TIFF_COMPRESSION_CCITT_GROUP_4: {
@@ -194,12 +197,12 @@ public abstract class ImageDataReader {
                 throw new ImageReadException(
                         "T.6 compression with the uncompressed mode extension is not yet
supported");
             }
-            return T4AndT6Compression.decompressT6(compressed, tileWidth,
+            return T4AndT6Compression.decompressT6(compressedOrdered, tileWidth,
                     tileHeight);
         }
         case TIFF_COMPRESSION_LZW: // LZW
         {
-            final InputStream is = new ByteArrayInputStream(compressed);
+            final InputStream is = new ByteArrayInputStream(compressedOrdered);
 
             final int lzwMinimumCodeSize = 8;
 
@@ -213,7 +216,7 @@ public abstract class ImageDataReader {
 
         case TIFF_COMPRESSION_PACKBITS: // Packbits
         {
-            return new PackBits().decompress(compressed, expectedSize);
+            return new PackBits().decompress(compressedOrdered, expectedSize);
         }
 
         default:



Mime
View raw message