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 2016/08/26 17:22:29 UTC
svn commit: r1757897 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
Author: tilman
Date: Fri Aug 26 17:22:29 2016
New Revision: 1757897
URL: http://svn.apache.org/viewvc?rev=1757897&view=rev
Log:
PDFBOX-3475: repair /Length2
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1757897&r1=1757896&r2=1757897&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Fri Aug 26 17:22:29 2016
@@ -235,9 +235,10 @@ public class PDType1Font extends PDSimpl
int length1 = stream.getInt(COSName.LENGTH1);
int length2 = stream.getInt(COSName.LENGTH2);
- // repair Length1 if necessary
+ // repair Length1 and Length2 if necessary
byte[] bytes = fontFile.toByteArray();
length1 = repairLength1(bytes, length1);
+ length2 = repairLength2(bytes, length1, length2);
if (bytes.length > 0 && (bytes[0] & 0xff) == PFB_START_MARKER)
{
@@ -341,6 +342,27 @@ public class PDType1Font extends PDSimpl
}
/**
+ * Some Type 1 fonts have an invalid Length2, see PDFBOX-3475. A negative /Length2 brings an
+ * IllegalArgumentException in Arrays.copyOfRange(), a huge value eats up memory because of
+ * padding.
+ *
+ * @param bytes Type 1 stream bytes
+ * @param length1 Length1 from the Type 1 stream
+ * @param length2 Length2 from the Type 1 stream
+ * @return repaired Length2 value
+ */
+ private int repairLength2(byte[] bytes, int length1, int length2)
+ {
+ // repair Length2 if necessary
+ if (length2 < 0 || length2 > bytes.length - length1)
+ {
+ LOG.warn("Ignored invalid Length2 " + length2 + " for Type 1 font " + getName());
+ length2 = bytes.length - length1;
+ }
+ return length2;
+ }
+
+ /**
* Returns the PostScript name of the font.
*/
public final String getBaseFont()