Skip to content

Math font parsing can crash too easily without a clear message #2333

@Omikhleia

Description

@Omikhleia

Pennstander is a quite recent whimsical/fanciful text and mathematics, with several styles and weights.

I wanted to test one of its math fonts1, but just made a blunder, using Pennstander-Light.otf instead of PennstanderMath-Light.otf.

Error: runtime error: (...)/vstruct/ast/IO.lua:35: attempt to read past end of buffer
stack traceback:
	(...)/vstruct/ast/IO.lua:35: in function 'read'
	(...)/vstruct/init.lua:76: in function 'readvals'
	(...)/core/opentype-parser.lua:441: in function 'parseCoverage'
	(...)/core/opentype-parser.lua:625: in function 'parseIfPresent'
	(...)/core/opentype-parser.lua:757: in function 'parseMath'
        (...)

I am no expert, but ttx can parse it -- and it seems that this font does have a MATH table, but with no MathGlyphInfo and MathVariants sub-tables It only has the MathConstants table, but moreover are fields are zero-valued...2

So it's a bit as in #2323 :
When provided the wrong font, the font parser (or later math-related code) can crash with an obscure stack trace.

It was all my mistake here, but surely we can make the math table parser a bit more robust and error with something helpful.
I'd have appreciated "Font (family or filename) does not seem to be a math-capable font (... and some details ...)"
It's possible (or I assume ?) for some tables to be absent, but in that case we'd need to behave adequately.

Footnotes

  1. For curious readers, I was also testing a few Math fonts such as Garamond Math, Luciole Math, Lete Sans Math, in addition the more usual Libertinus Math and STIX Two Math; there are issues with these (missing characters, etc.) which would require some analysis (esp. in our current handling of accents), but they "globally" work decently. And so does Pennstander Math Light, lol -- with some other issue (some non-rendered elements in a complex formula), but otherwise quite nice.

  2. Maybe it's something to report. Other tools also might think they are using a math font due to the presence of the table. It's confusing at best, 'cause otfinfo -t etc. will show it has a MATH table... So I didn't understood my blunder immediately. EDIT: Reported to their repo on GitHub.

Metadata

Metadata

Assignees

No one assigned

    Labels

    modules:packagesIssue relates to core or 3rd party packagesrefactorCode quality improvements

    Type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions