pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1772121 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/graphics/image/ test/java/org/apache/pdfbox/pdmodel/graphics/image/ test/resources/org/apache/pdfbox/pdmodel/graphics/image/
Date Wed, 30 Nov 2016 21:14:29 GMT
Author: tilman
Date: Wed Nov 30 21:14:29 2016
New Revision: 1772121

URL: http://svn.apache.org/viewvc?rev=1772121&view=rev
Log:
PDFBOX-3608: ignore garbage in big endian byte/short tiff tags, as suggested by Št?pán Schejbal

Added:
    pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields-bigendian.tif
  (with props)
    pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields.tif
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java?rev=1772121&r1=1772120&r2=1772121&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
Wed Nov 30 21:14:29 2016
@@ -306,35 +306,26 @@ public final class CCITTFactory
                 int tag = readshort(endianess, reader);
                 int type = readshort(endianess, reader);
                 int count = readlong(endianess, reader);
-                int val = readlong(endianess, reader); // See note
-
-                // Note, we treated that value as a long. The value always occupies 4 bytes
-                // But it might only use the first byte or two. Depending on endianess we
might
-                // need to correct.
-                // Note we ignore all other types, they are of little interest for PDFs/CCITT
Fax
-                if (endianess == 'M')
+                int val;
+                // Note that when the type is shorter than 4 bytes, the rest can be garbage
+                // and must be ignored. E.g. short (2 bytes) from "01 00 38 32" (little endian)
+                // is 1, not 842530817 (seen in a real-life TIFF image).
+                switch (type)
                 {
-                    switch (type)
-                    {
-                        case 1:
-                        {
-                            val = val >> 24;
-                            break; // byte value
-                        }
-                        case 3:
-                        {
-                            val = val >> 16;
-                            break; // short value
-                        }
-                        case 4:
-                        {
-                            break; // long value
-                        }
-                        default:
-                        {
-                            // do nothing
-                        }
-                    }
+                    case 1: // byte value
+                        val = reader.read();
+                        reader.read();
+                        reader.read();
+                        reader.read();
+                        break;
+                    case 3: // short value
+                        val = readshort(endianess, reader);
+                        reader.read();
+                        reader.read();
+                        break;
+                    default: // long and other types
+                        val = readlong(endianess, reader);
+                        break;
                 }
                 switch (tag)
                 {

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java?rev=1772121&r1=1772120&r2=1772121&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Wed Nov 30 21:14:29 2016
@@ -22,6 +22,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Arrays;
 import javax.imageio.ImageIO;
 import javax.imageio.ImageReader;
 import javax.imageio.stream.ImageInputStream;
@@ -231,6 +232,23 @@ public class CCITTFactoryTest extends Te
         assertTrue(copiedTiffFile.delete());
     }
 
+    /**
+     * Tests that byte/short tag values are read correctly (ignoring possible garbage in
remaining
+     * bytes).
+     */
+    public void testByteShortPaddedWithGarbage() throws IOException
+    {
+        PDDocument document = new PDDocument();
+        String basePath = "src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields";
+        for (String ext : Arrays.asList(".tif", "-bigendian.tif"))
+        {
+            String tiffPath = basePath + ext;
+            PDImageXObject ximage3 = CCITTFactory.createFromFile(document, new File(tiffPath));
+            validate(ximage3, 1, 344, 287, "tiff", PDDeviceGray.INSTANCE.getName());
+        }
+        document.close();
+    }
+
     private void copyFile(File source, File dest) throws IOException
     {
         InputStream is = null;

Added: pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields-bigendian.tif
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields-bigendian.tif?rev=1772121&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields-bigendian.tif
------------------------------------------------------------------------------
    svn:mime-type = image/tiff

Added: pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields.tif
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields.tif?rev=1772121&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/trunk/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg3-garbage-padded-fields.tif
------------------------------------------------------------------------------
    svn:mime-type = image/tiff



Mime
View raw message