Martin Mirchev created PDFBOX-6328:
--------------------------------------
Summary: ArrayIndexOutOfBoundsException when a CFF font has more
fonts in its Name INDEX than entries in its Top DICT INDEX
Key: PDFBOX-6328
URL: https://issues.apache.org/jira/browse/PDFBOX-6328
Project: PDFBox
Issue Type: Bug
Components: FontBox
Affects Versions: 4.0.0, 3.0.8 PDFBox
Reporter: Martin Mirchev
Attachments: cff-ok.pdf, cff-two-names.pdf
{{CFFParser.parse()}} reads {{topDictIndex[i]}} for every entry of the Name
INDEX without checking that the Top DICT INDEX has as many entries. A CFF whose
Name INDEX lists two fonts but whose Top DICT INDEX has one throws:
{code}
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at org.apache.fontbox.cff.CFFParser.parse(CFFParser.java:214)
{code}
{{PDType1CFont}} catches only {{IOException}} around the parse, so for a PDF
with such a font embedded ({{FontFile3}}, {{/Subtype /Type1C}}) the exception
escapes {{PDFRenderer.renderImage()}} and {{PDFTextStripper.getText()}}.
Attached {{cff-two-names.pdf}} embeds {{FoglihtenNo07.otf}}'s CFF (from the
fontbox test resources) with its Name INDEX rewritten in place to two names
(same length, offsets unchanged); {{cff-ok.pdf}} embeds the unmodified CFF and
renders and extracts normally (3/3 runs each).
A possible change: reject the font when the Top DICT INDEX is shorter than the
Name INDEX. With it, {{cff-two-names.pdf}} logs "Can't read the embedded Type1C
font", renders and extracts text with the fallback font:
{code}
--- a/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
+++ b/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
@@ -205,6 +205,12 @@
throw new IOException("Top DICT INDEX missing in CFF font");
}
+ if (topDictIndex.length < nameIndex.length)
+ {
+ throw new IOException("Top DICT INDEX has " + topDictIndex.length
+ + " entries for " + nameIndex.length + " fonts in the Name
INDEX");
+ }
+
stringIndex = readStringIndexData(input);
byte[][] globalSubrIndex = readIndexData(input);
{code}
This issue was found by an LLM-assisted tool and verified manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]