Avoid infinite recursion while compiling a glyph

This commit is contained in:
Calixte Denizet 2026-04-10 18:55:01 +02:00 committed by calixteman
parent 006931f3d3
commit b4d689ce06
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
4 changed files with 17 additions and 2 deletions

View File

@ -168,7 +168,13 @@ function lookupCmap(ranges, unicode) {
};
}
function compileGlyf(code, cmds, font) {
function compileGlyf(code, cmds, font, visitedGlyphs = new Set()) {
if (visitedGlyphs.has(code)) {
warn("compileGlyf: skipping recursive composite glyph reference.");
return;
}
visitedGlyphs.add(code);
function moveTo(x, y) {
if (firstPoint) {
// Close the current subpath in adding a straight line to the first point.
@ -250,7 +256,7 @@ function compileGlyf(code, cmds, font) {
// TODO: we must use arg1 and arg2 to make something similar to:
// https://github.com/freetype/freetype/blob/edd4fedc5427cf1cf1f4b045e53ff91eb282e9d4/src/truetype/ttgload.c#L1209
}
compileGlyf(subglyph, cmds, font);
compileGlyf(subglyph, cmds, font, visitedGlyphs);
cmds.restore();
}
} while (flags & 0x20);
@ -352,6 +358,7 @@ function compileGlyf(code, cmds, font) {
startPoint = endPoint + 1;
}
}
visitedGlyphs.delete(code);
}
function compileCharString(charStringCode, cmds, font, glyphId) {

View File

@ -899,3 +899,4 @@
!issue16091.pdf
!issue7821.pdf
!issue21068.pdf
!recursiveCompositGlyf.pdf

Binary file not shown.

View File

@ -14105,5 +14105,12 @@
"link": true,
"rounds": 1,
"type": "eq"
},
{
"id": "recursiveCompositGlyf",
"file": "pdfs/recursiveCompositGlyf.pdf",
"md5": "e4e106d20e4af10d7a5f1a5da02db66f",
"rounds": 1,
"type": "eq"
}
]