pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1782244 - in /pdfbox/trunk: fontbox/src/main/java/org/apache/fontbox/type1/Type1Parser.java pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
Date Wed, 08 Feb 2017 19:45:35 GMT
Author: tilman
Date: Wed Feb  8 19:45:35 2017
New Revision: 1782244

URL: http://svn.apache.org/viewvc?rev=1782244&view=rev
Log:
PDFBOX-3677: search for eexec in both directions; remove blank skip from isBinary()

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Parser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Parser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Parser.java?rev=1782244&r1=1782243&r2=1782244&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Parser.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/type1/Type1Parser.java Wed Feb 
8 19:45:35 2017
@@ -837,18 +837,11 @@ final class Type1Parser
         {
             return true;
         }
-        byte by = bytes[0];
-        // The first ciphertext byte must not be an ASCII white space
-        // character code (blank, tab, carriage return or line feed).
-        if (by != 0x0a && by != 0x0d && by != 0x20 && by != '\t')
-        {
-            return true;
-        }
         // "At least one of the first 4 ciphertext bytes must not be one of
         // the ASCII hexadecimal character codes (a code for 0-9, A-F, or a-f)."
         for (int i = 0; i < 4; ++i)
         {
-            by = bytes[i];
+            byte by = bytes[i];
             if (by != 0x0a && by != 0x0d && by != 0x20 && by != '\t'
&& 
                     Character.digit((char) by, 16) == -1)
             {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1782244&r1=1782243&r2=1782244&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Wed
Feb  8 19:45:35 2017
@@ -302,7 +302,7 @@ public class PDType1Font extends PDSimpl
 
     /**
      * Some Type 1 fonts have an invalid Length1, which causes the binary segment of the
font
-     * to be truncated, see PDFBOX-2350.
+     * to be truncated, see PDFBOX-2350, PDFBOX-3677.
      *
      * @param bytes Type 1 stream bytes
      * @param length1 Length1 from the Type 1 stream
@@ -316,22 +316,12 @@ public class PDType1Font extends PDSimpl
         {
             offset = bytes.length - 4;
         }
-        while (offset > 0)
+
+        offset = findBinaryOffsetAfterExec(bytes, offset);
+        if (offset == 0 && length1 > 0)
         {
-            if (bytes[offset + 0] == 'e' &&
-                bytes[offset + 1] == 'x' &&
-                bytes[offset + 2] == 'e' &&
-                bytes[offset + 3] == 'c')
-            {
-                offset += 4;
-                // skip additional CR LF space characters
-                while (offset < length1 && (bytes[offset] == '\r' || bytes[offset]
== '\n' || bytes[offset] == ' '))
-                {
-                    offset++;
-                }
-                break;
-            }
-            offset--;
+            // 2nd try with brute force
+            offset = findBinaryOffsetAfterExec(bytes, bytes.length - 4);
         }
 
         if (length1 - offset != 0 && offset > 0)
@@ -346,6 +336,31 @@ public class PDType1Font extends PDSimpl
         return length1;
     }
 
+    private static int findBinaryOffsetAfterExec(byte[] bytes, int startOffset)
+    {
+        int offset = startOffset;
+        while (offset > 0)
+        {
+            if (bytes[offset + 0] == 'e'
+                    && bytes[offset + 1] == 'x'
+                    && bytes[offset + 2] == 'e'
+                    && bytes[offset + 3] == 'c')
+            {
+                offset += 4;
+                // skip additional CR LF space characters
+                while (offset < bytes.length && 
+                        (bytes[offset] == '\r' || bytes[offset] == '\n' || 
+                         bytes[offset] == ' ' || bytes[offset] == '\t'))
+                {
+                    offset++;
+                }
+                break;
+            }
+            offset--;
+        }
+        return offset;
+    }
+
     /**
      * Some Type 1 fonts have an invalid Length2, see PDFBOX-3475. A negative /Length2 brings
an
      * IllegalArgumentException in Arrays.copyOfRange(), a huge value eats up memory because
of



Mime
View raw message