foliojs / fontkit

An advanced font engine for Node and the browser
1.45k stars 213 forks source link

fix bug #244

Closed thehandsomepanther closed 3 years ago

thehandsomepanther commented 3 years ago

We depend on the fontkit module for generating SVGs font fonts, and we discovered that it's possible to enter an infinite loop when trying to layout a font with multiple substitutions. Basically the GSUBProcessor's applyLookup function can add elements onto this.glyphs, which is a reference to the same array that we use to determine the termination condition of the while loop in OTProcessor's applyLookups.

So the problem is that we can add >1 glyph onto glyphs via applyLookup but we only ever increment this.glyphIterator by 1, which causes this.glyphIterator.index < glyphs.length to always return false.

I dont know very much about fonts, so I would love feedback on this fix if it's not semantically correct! I've run the test suite provided via npm run test and all tests continue to pass. Thanks for making fontkit!