You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2023/03/28 06:38:53 UTC

svn commit: r1908760 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java

Author: lehmi
Date: Tue Mar 28 06:38:53 2023
New Revision: 1908760

URL: http://svn.apache.org/viewvc?rev=1908760&view=rev
Log:
PDFBOX-5582: don't use the given number of objects to initialize the list to avoid an OOME

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1908760&r1=1908759&r2=1908760&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Tue Mar 28 06:38:53 2023
@@ -2051,7 +2051,11 @@ public class COSParser extends BaseParse
                         securityHandler.decryptStream(stream, stmObjNumber, stmGenNumber);
                     }
                     PDFObjectStreamParser strmParser = new PDFObjectStreamParser(stream, document);
-                    objectNumbers = new ArrayList<Long>(nrOfObjects);
+                    // don't use "nrOfObjects" to initialize the list as a malformed pdf might
+                    // contain an invalid value which may lead to an out of memory exception
+                    // if the number is to big the following code will most likely fail hitting
+                    // the end of the stream prematurely
+                    objectNumbers = new ArrayList<Long>();
                     for (int i = 0; i < nrOfObjects; i++)
                     {
                         objectNumbers.add(strmParser.readObjectNumber());