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 2021/04/13 06:17:13 UTC
svn commit: r1888706 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
Author: lehmi
Date: Tue Apr 13 06:17:13 2021
New Revision: 1888706
URL: http://svn.apache.org/viewvc?rev=1888706&view=rev
Log:
PDFBOX-5163: stop reading corrupted dictionaries to avoid a stack overflow exception
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1888706&r1=1888705&r2=1888706&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Tue Apr 13 06:17:13 2021
@@ -154,7 +154,7 @@ public abstract class BaseParser
COSBase value = parseDirObject();
skipSpaces();
// proceed if the given object is a number and the following is a number as well
- if (!(value instanceof COSNumber) || !isDigit())
+ if ((!(value instanceof COSNumber) || !isDigit()))
{
return value;
}
@@ -213,7 +213,12 @@ public abstract class BaseParser
}
else if (c == '/')
{
- parseCOSDictionaryNameValuePair(obj);
+ // something went wrong, most likely the dictionary is corrupted
+ // stop immediately and return everything read so far
+ if (!parseCOSDictionaryNameValuePair(obj))
+ {
+ return obj;
+ }
}
else
{
@@ -277,7 +282,7 @@ public abstract class BaseParser
return false;
}
- private void parseCOSDictionaryNameValuePair(COSDictionary obj) throws IOException
+ private boolean parseCOSDictionaryNameValuePair(COSDictionary obj) throws IOException
{
COSName key = parseCOSName();
COSBase value = parseCOSDictionaryValue();
@@ -300,6 +305,7 @@ public abstract class BaseParser
if (value == null)
{
LOG.warn("Bad dictionary declaration at offset " + seqSource.getPosition());
+ return false;
}
else
{
@@ -307,6 +313,7 @@ public abstract class BaseParser
value.setDirect(true);
obj.setItem(key, value);
}
+ return true;
}
protected void skipWhiteSpaces() throws IOException