You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/12/14 10:18:44 UTC
svn commit: r1884410 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
Author: tilman
Date: Mon Dec 14 10:18:44 2020
New Revision: 1884410
URL: http://svn.apache.org/viewvc?rev=1884410&view=rev
Log:
PDFBOX-4892: avoid ClassCastException and NullPointerException and IndexOutOfBoundsException
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java?rev=1884410&r1=1884409&r2=1884410&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3Font.java Mon Dec 14 10:18:44 2020
@@ -19,6 +19,7 @@ package org.apache.pdfbox.pdmodel.font;
import java.awt.geom.GeneralPath;
import java.io.IOException;
import java.io.InputStream;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fontbox.FontBoxFont;
@@ -149,9 +150,14 @@ public class PDType3Font extends PDSimpl
{
int firstChar = dict.getInt(COSName.FIRST_CHAR, -1);
int lastChar = dict.getInt(COSName.LAST_CHAR, -1);
- if (!getWidths().isEmpty() && code >= firstChar && code <= lastChar)
+ List<Float> widths = getWidths();
+ if (!widths.isEmpty() && code >= firstChar && code <= lastChar)
{
- Float w = getWidths().get(code - firstChar);
+ if (code - firstChar >= widths.size())
+ {
+ return 0;
+ }
+ Float w = widths.get(code - firstChar);
return w == null ? 0 : w;
}
else
@@ -355,7 +361,7 @@ public class PDType3Font extends PDSimpl
{
if (charProcs == null)
{
- charProcs = (COSDictionary) dict.getDictionaryObject(COSName.CHAR_PROCS);
+ charProcs = dict.getCOSDictionary(COSName.CHAR_PROCS);
}
return charProcs;
}
@@ -369,10 +375,14 @@ public class PDType3Font extends PDSimpl
public PDType3CharProc getCharProc(int code)
{
String name = getEncoding().getName(code);
- COSBase base = getCharProcs().getDictionaryObject(COSName.getPDFName(name));
- if (base instanceof COSStream)
+ if (getCharProcs() == null)
+ {
+ return null;
+ }
+ COSStream stream = getCharProcs().getCOSStream(COSName.getPDFName(name));
+ if (stream != null)
{
- return new PDType3CharProc(this, (COSStream) base);
+ return new PDType3CharProc(this, stream);
}
return null;
}