pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1810019 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Date Thu, 28 Sep 2017 17:43:02 GMT
Author: lehmi
Date: Thu Sep 28 17:43:02 2017
New Revision: 1810019

URL: http://svn.apache.org/viewvc?rev=1810019&view=rev
Log:
PDFBOX-3934: skip trailing spaces

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1810019&r1=1810018&r2=1810019&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Thu Sep 28
17:43:02 2017
@@ -764,14 +764,6 @@ public class COSParser extends BaseParse
             // ---- read offset or object stream object number from xref table
             Long offsetOrObjstmObNr = document.getXrefTable().get(objKey);
 
-            // sanity test to circumvent loops with broken documents
-            if (requireExistingNotCompressedObj
-                    && ((offsetOrObjstmObNr == null) || (offsetOrObjstmObNr <=
0)))
-            {
-                throw new IOException("Object must be defined and must not be compressed
object: "
-                        + objKey.getNumber() + ":" + objKey.getGeneration());
-            }
-
             // maybe something is wrong with the xref table -> perform brute force search
for all objects
             if (offsetOrObjstmObNr == null && isLenient)
             {
@@ -784,6 +776,14 @@ public class COSParser extends BaseParse
                 }
             }
 
+            // sanity test to circumvent loops with broken documents
+            if (requireExistingNotCompressedObj
+                    && ((offsetOrObjstmObNr == null) || (offsetOrObjstmObNr <=
0)))
+            {
+                throw new IOException("Object must be defined and must not be compressed
object: "
+                        + objKey.getNumber() + ":" + objKey.getGeneration());
+            }
+
             if (offsetOrObjstmObNr == null)
             {
                 // not defined object -> NULL object (Spec. 1.7, chap. 3.2.9)
@@ -1783,11 +1783,19 @@ public class COSParser extends BaseParse
                 int nrOfObjects = dict.getInt(COSName.N);
                 COSStream stream = parseCOSStream(dict);
                 COSInputStream is = stream.createInputStream();
-                byte[] numbersStr = new byte[offsetFirstStream];
-                is.read(numbersStr);
+                byte[] numbersBytes = new byte[offsetFirstStream];
+                is.read(numbersBytes);
                 is.close();
                 stream.close();
-                String[] numbers = new String(numbersStr, "ISO-8859-1").split(" ");
+                int start = 0;
+                // skip spaces
+                while (numbersBytes[start] == 32)
+                {
+                    start++;
+                }
+                String numbersStr = new String(numbersBytes, start, numbersBytes.length -
start,
+                        "ISO-8859-1");
+                String[] numbers = numbersStr.split(" ");
                 for (int i = 0; i < nrOfObjects; i++)
                 {
                     long objNumber = Long.parseLong(numbers[i * 2]);



Mime
View raw message