Hi,

I'm currently working on the PDFBOX-1398 [1] issue.
An ArrayOutOfBound Exception is thrown on TrueType font file parsing. (A
embedded fontfile in the CIDType2Font dictionary)

The problem comes from the "glyphIdToCharacterCode" array that haven't the
right size in the "processSubtype4" method.
(This array is initialized with "new int[numGlyphs]" where numGlyphs
contains the number of glyph present in the MaxProfile table of the Font)

At the beginning, I thought that the font was damaged, but in the TrueType
Font specification [2] there is this comment for the glyphIdArray
description in the SubType4 for the CMap table : Glyph index array
(arbitrary length)

Does that mean the GlyphIdArray doesn't have a size based on the number of
declared glyphs in the MaxProfile table and can have some glyph identifiers
that will be mapped on the ".notdef" glyph if this index is used ?

In other words, can we extend the "glyphIdToCharacterCode" if the computed
glyph index is bigger than the length of array (see example here after) ? I
didn't see any error on variables initialization in this method that could
explain a wrong size of array and the extracted font stream seems to be a
valid font when I open it with FontForge.

                        int glyphid = (j+delta)%65536;
                        if (glyphid >= glyphIdToCharacterCode.length) {
                            glyphIdToCharacterCode =
Arrays.copyOf(glyphIdToCharacterCode, glyphid+1);
                        }
                        glyphIdToCharacterCode[ glyphid ]=j;
                        characterCodeToGlyphId.put(j, glyphid);


An other possibility is throwing an explicit  RuntimeException specifying
that the number of glyph inside the FontFile is inconsistent.

What is your opinion?

BR,
Eric

[1] https://issues.apache.org/jira/browse/PDFBOX-1398
[2] http://www.microsoft.com/typography/otspec/cmap.htm

Reply via email to