pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1692714 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Date Sun, 26 Jul 2015 11:17:31 GMT
Author: lehmi
Date: Sun Jul 26 11:17:30 2015
New Revision: 1692714

URL: http://svn.apache.org/r1692714
Log:
PDFBOX-2845: limit the check for /Length being an indirect object to object streams, removed
the recursion check in getLength

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1692714&r1=1692713&r2=1692714&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Sun Jul 26 11:17:30 2015
@@ -1605,74 +1605,55 @@ public class NonSequentialPDFParser exte
         }
     }
 
-    // ------------------------------------------------------------------------
-    private boolean inGetLength = false;
-
     /** Returns length value referred to or defined in given object. */
-    private COSNumber getLength(final COSBase lengthBaseObj) throws IOException
+    private COSNumber getLength(final COSBase lengthBaseObj, final COSBase streamType) throws
IOException
     {
         if (lengthBaseObj == null)
         {
             return null;
         }
-
-        if (inGetLength)
+        COSNumber retVal = null;
+        // ---- maybe length was given directly
+        if (lengthBaseObj instanceof COSNumber)
         {
-            throw new IOException("Loop while reading length from " + lengthBaseObj);
+            retVal = (COSNumber) lengthBaseObj;
         }
-
-        COSNumber retVal = null;
-
-        try
+        // ---- length in referenced object
+        else if (lengthBaseObj instanceof COSObject)
         {
-            inGetLength = true;
+            COSObject lengthObj = (COSObject) lengthBaseObj;
 
-            // ---- maybe length was given directly
-            if (lengthBaseObj instanceof COSNumber)
+            if (lengthObj.getObject() == null)
             {
-                retVal = (COSNumber) lengthBaseObj;
-            }
-            // ---- length in referenced object
-            else if (lengthBaseObj instanceof COSObject)
-            {
-                COSObject lengthObj = (COSObject) lengthBaseObj;
-
-                if (lengthObj.getObject() == null)
-                {
-                    // not read so far
-
-                    // keep current stream position
-                    final long curFileOffset = getPdfSourceOffset();
-                    releasePdfSourceInputStream();
+                // not read so far
 
-                    parseObjectDynamically(lengthObj, true);
+                // keep current stream position
+                final long curFileOffset = getPdfSourceOffset();
+                releasePdfSourceInputStream();
+                boolean isObjectStream = COSName.OBJ_STM.equals(streamType);
+                parseObjectDynamically(lengthObj, isObjectStream);
 
-                    // reset current stream position
-                    setPdfSource(curFileOffset);
+                // reset current stream position
+                setPdfSource(curFileOffset);
 
-                    if (lengthObj.getObject() == null)
-                    {
-                        throw new IOException("Length object content was not read.");
-                    }
-                }
-
-                if (!(lengthObj.getObject() instanceof COSNumber))
+                if (lengthObj.getObject() == null)
                 {
-                    throw new IOException("Wrong type of referenced length object " + lengthObj
+ ": "
-                            + lengthObj.getObject().getClass().getSimpleName());
+                    throw new IOException("Length object content was not read.");
                 }
-
-                retVal = (COSNumber) lengthObj.getObject();
-
             }
-            else
+
+            if (!(lengthObj.getObject() instanceof COSNumber))
             {
-                throw new IOException("Wrong type of length object: " + lengthBaseObj.getClass().getSimpleName());
+                throw new IOException("Wrong type of referenced length object " + lengthObj
+ ": "
+                        + lengthObj.getObject().getClass().getSimpleName());
             }
+
+            retVal = (COSNumber) lengthObj.getObject();
+
         }
-        finally
+        else
         {
-            inGetLength = false;
+            throw new IOException("Wrong type of length object: " + lengthBaseObj.getClass().getSimpleName());
         }
         return retVal;
     }
@@ -1742,7 +1723,7 @@ public class NonSequentialPDFParser exte
             /*
              * This needs to be dic.getItem because when we are parsing, the underlying object
might still be null.
              */
-            COSNumber streamLengthObj = getLength(dic.getItem(COSName.LENGTH));
+            COSNumber streamLengthObj = getLength(dic.getItem(COSName.LENGTH), dic.getItem(COSName.TYPE));
             if (streamLengthObj == null)
             {
                 if (isLenient)



Mime
View raw message