pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1811483 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Date Sun, 08 Oct 2017 12:27:14 GMT
Author: lehmi
Date: Sun Oct  8 12:27:13 2017
New Revision: 1811483

URL: http://svn.apache.org/viewvc?rev=1811483&view=rev
Log:
PDFBOX-3628: skip corrupt streams when performing a brute force search for object streams

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java   (contents,
props changed)

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=1811483&r1=1811482&r2=1811483&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 Sun Oct 
8 12:27:13 2017
@@ -1752,15 +1752,37 @@ public class COSParser extends BaseParse
                 long stmObjNumber = readObjectNumber();
                 readGenerationNumber();
                 readExpectedString(OBJ_MARKER, true);
-                COSDictionary dict = parseCOSDictionary();
-                int offsetFirstStream = dict.getInt(COSName.FIRST);
-                int nrOfObjects = dict.getInt(COSName.N);
-                COSStream stream = parseCOSStream(dict);
-                COSInputStream is = stream.createInputStream();
-                byte[] numbersBytes = new byte[offsetFirstStream];
-                is.read(numbersBytes);
-                is.close();
-                stream.close();
+                int nrOfObjects = 0;
+                byte[] numbersBytes = null;
+                COSStream stream = null;
+                COSInputStream is = null;
+                try
+                {
+                    COSDictionary dict = parseCOSDictionary();
+                    int offsetFirstStream = dict.getInt(COSName.FIRST);
+                    nrOfObjects = dict.getInt(COSName.N);
+                    stream = parseCOSStream(dict);
+                    is = stream.createInputStream();
+                    numbersBytes = new byte[offsetFirstStream];
+                    is.read(numbersBytes);
+                }
+                catch (IOException exception)
+                {
+                    LOG.debug(
+                            "Skipped corrupt stream: (" + stmObjNumber + " 0 at offset "
+ offset);
+                    continue;
+                }
+                finally
+                {
+                    if (is != null)
+                    {
+                        is.close();
+                    }
+                    if (stream != null)
+                    {
+                        stream.close();
+                    }
+                }
                 int start = 0;
                 // skip spaces
                 while (numbersBytes[start] == 32)

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Oct  8 12:27:13 2017
@@ -1,4 +1,4 @@
 /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:1641458
-/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java:1779822,1780783,1792784,1792839,1795704,1795712
+/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java:1779822,1780783,1792784,1792839,1795704,1795712,1811482
 /pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:1618517-1621410
 /pdfbox/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:1618514-1618516



Mime
View raw message