pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1724314 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
Date Tue, 12 Jan 2016 20:37:02 GMT
Author: tilman
Date: Tue Jan 12 20:37:02 2016
New Revision: 1724314

URL: http://svn.apache.org/viewvc?rev=1724314&view=rev
Log:
PDFBOX-3189: don't read overlong numbers to avoid pushback exception
PDFBOX-2852: add comment; improve log msg

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1724314&r1=1724313&r2=1724314&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Tue Jan
12 20:37:02 2016
@@ -50,6 +50,8 @@ public abstract class BaseParser
 
     private static final long GENERATION_NUMBER_THRESHOLD = 65535;
 
+    static final int MAX_LENGTH_LONG = Long.toString(Long.MAX_VALUE).length();
+
     /**
      * Log instance.
      */
@@ -207,7 +209,7 @@ public abstract class BaseParser
             else
             {
                 // invalid dictionary, we were expecting a /Name, read until the end or until
we can recover
-                LOG.warn("Invalid dictionary, found: '" + c + "' but expected: '/'");
+                LOG.warn("Invalid dictionary, found: '" + c + "' but expected: '/' at offset
" + seqSource.getPosition());
                 if (readUntilEndOfCOSDictionary())
                 {
                     // we couldn't recover
@@ -292,6 +294,7 @@ public abstract class BaseParser
         }
         else
         {
+            // label this item as direct, to avoid signature problems.
             value.setDirect(true);
             obj.setItem(key, value);
         }
@@ -1364,6 +1367,11 @@ public abstract class BaseParser
                 lastByte != -1 )
         {
             buffer.append( (char)lastByte );
+            if (buffer.length() > MAX_LENGTH_LONG)
+            {
+                throw new IOException("Number '" + buffer + 
+                        "' is getting too long, stop reading at offset " + seqSource.getPosition());
+            }
         }
         if( lastByte != -1 )
         {



Mime
View raw message