You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by "plutext (via GitHub)" <gi...@apache.org> on 2026/10/02 21:34:30 UTC
[PR] FOP-3339: An empty glyph is never composite; the subsetter read past the glyf table and the font was not embedded [xmlgraphics-fop]
plutext opened a new pull request, #108:
URL: https://github.com/apache/xmlgraphics-fop/pull/108
Fixes [FOP-3339](https://issues.apache.org/jira/browse/FOP-3339).
JIRA: to be filed
GlyfTable.isComposite reads a 2-byte numberOfContours at the glyph's offset in
the glyf table, without checking the glyph's length. A glyph whose loca entry
gives it a length of zero has no glyph description at all, so those two bytes
are the next glyph's numberOfContours - and when the empty glyph is the last in
the font and glyf is the last table in the file, they are past the end of it:
```
java.io.EOFException: Reached EOF, file size=593908
at org.apache.fop.fonts.truetype.FontFileReader.read(FontFileReader.java:100)
at org.apache.fop.fonts.truetype.GlyfTable.isComposite(GlyfTable.java:206)
at org.apache.fop.fonts.truetype.GlyfTable.scanGlyphsRecursively(GlyfTable.java:156)
at org.apache.fop.fonts.truetype.GlyfTable.populateGlyphsWithComposites(GlyfTable.java:126)
at org.apache.fop.fonts.truetype.TTFSubSetFile.scanGlyphs(TTFSubSetFile.java:572)
at org.apache.fop.pdf.PDFFactory.getFontSubsetBytes(PDFFactory.java:1482)
at org.apache.fop.pdf.PDFFactory.makeFontFile(PDFFactory.java:1406)
at org.apache.fop.pdf.PDFFactory.makeFont(PDFFactory.java:970)
```
PDFFactory.makeFontFile catches it, logs it and returns null, so the font
descriptor is written with no /FontFile2. The PDF then names a font it does not
embed: it fails PDF/A, and a reader or printer without that font substitutes
another. Nothing else fails and the text is still drawn, which is why this goes
unnoticed.
Reproducer - subset any font whose last glyph is empty and whose glyf table
ends the file, with that glyph in the subset:
```
FontFileReader in = new FontFileReader(new FileInputStream("Carlito-Regular.ttf"));
Map<Integer, Integer> glyphs = new HashMap<>();
glyphs.put(0, 0);
glyphs.put(2531, 1); // the last glyph, U+00A0, empty
new TTFSubSetFile().readFont(in, "probe", null, glyphs); // EOFException
```
(Carlito 1.104: 593,908 bytes, numGlyphs 2532, glyf at 121,352 of length
472,556 - so the last glyph begins at exactly the end of the file. With glyph
2530 instead of 2531 the same call returns a 4,908-byte subset.)
Fonts of this shape are not exotic. The last glyph of Arimo and of Carlito -
the metric-compatible Arial and Calibri substitutes in Google's croscore and
crosextra families, which most Linux distributions package - is U+00A0, it is
empty, and glyf is the last table in the file. Whether the read runs off the
end then depends only on how many pad bytes follow, and measured against
TTFSubSetFile over the eight faces, five have fewer than two:
```
Arimo-Regular.ttf 2 bytes after the last glyph's offset ok
Arimo-Bold.ttf 0 EOFException
Arimo-Italic.ttf 1 EOFException
Arimo-BoldItalic.ttf 1 EOFException
Carlito-Regular.ttf 0 EOFException
Carlito-Bold.ttf 2 ok
Carlito-Italic.ttf 0 EOFException
Carlito-BoldItalic.ttf 3 ok
```
So a document with a non-breaking space in an Arial or Calibri run loses that
font from the PDF. Measured over a 449-document corpus of real documents, four
were affected, and in one of them the font that went missing was the body font
of the whole document.
So return false for an empty glyph without reading it: it is not composite,
whatever the bytes at its offset happen to say. That also fixes an empty glyph
in the middle of the table, whose two bytes are the next glyph's count - an
empty glyph immediately before a composite one was reported composite, and then
walked as one. The glyph's length is the next entry's offset in mtxTab, or the
glyf table's own length for the last glyph, which the constructor now keeps
from the OFDirTabEntry it is already handed; no signature changes, so the two
PCL callers are untouched (both already pass the font's full getMtx() and the
real glyf directory entry). TTFFile.readGlyf guards its own read of the same
bytes in the same way, breaking out when lastLoca equals the glyph's offset.
Adds GlyfTableTestCase.testEmptyLastGlyphIsNotReadPastTheEndOfTheFile and
testEmptyGlyphIsNotComposite over a synthetic glyf/loca, no font in
test/resources having the shape. They are phrased as what must be true rather
than as "this throws", so they still hold with the fix in. GlyfTableTestCase is
6/0; the fop-core suite is unchanged, its 4 failures and 8 errors being the
same ones before and after (all the stale ~/.fop/fop-fonts.cache
ClassCastException on this machine), and checkstyle reports 0 violations.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org
Re: [PR] FOP-3339: An empty glyph is never composite; the subsetter read past the glyf table and the font was not embedded [xmlgraphics-fop]
Posted by "plutext (via GitHub)" <gi...@apache.org>.
plutext closed pull request #108: FOP-3339: An empty glyph is never composite; the subsetter read past the glyf table and the font was not embedded
URL: https://github.com/apache/xmlgraphics-fop/pull/108
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org
Re: [PR] FOP-3339: An empty glyph is never composite; the subsetter read past the glyf table and the font was not embedded [xmlgraphics-fop]
Posted by "plutext (via GitHub)" <gi...@apache.org>.
plutext commented on PR #108:
URL: https://github.com/apache/xmlgraphics-fop/pull/108#issuecomment-6044415221
Closing: FOP-3352 (b1675d877, merged 2026-10-05) guards the last-glyph case, which is the EOFException this reported, and FOP-3339 is resolved as its duplicate.
This change guarded any empty glyph, not only the last: a mid-table empty glyph has no glyph description, so isComposite reads its successor's contour count, and when that is negative the empty glyph is treated as composite. That is a misread rather than a crash. If the general form is wanted, say so and I will rebase it as a follow-up on top of FOP-3352.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org