Don't crash when post format 1 is improperly used

Fixes #2736
This commit is contained in:
Miguel Sousa 2022-08-29 06:35:45 -07:00
parent 55192edb0c
commit 0e9c48e6ab
3 changed files with 15 additions and 0 deletions

View File

@ -487,6 +487,13 @@ class TTFont(object):
# in combination with the Adobe Glyph List (AGL). # in combination with the Adobe Glyph List (AGL).
# #
self._getGlyphNamesFromCmap() self._getGlyphNamesFromCmap()
elif len(glyphOrder) < self['maxp'].numGlyphs:
#
# Not enough names found in the 'post' table.
# Can happen when 'post' format 1 is improperly used on a font that
# has more than 258 glyphs (the lenght of 'standardGlyphOrder').
#
self._getGlyphNamesFromCmap()
else: else:
self.glyphOrder = glyphOrder self.glyphOrder = glyphOrder
else: else:

Binary file not shown.

View File

@ -4,6 +4,7 @@ import re
import random import random
from fontTools.feaLib.builder import addOpenTypeFeaturesFromString from fontTools.feaLib.builder import addOpenTypeFeaturesFromString
from fontTools.ttLib import TTFont, TTLibError, newTable, registerCustomTableClass, unregisterCustomTableClass from fontTools.ttLib import TTFont, TTLibError, newTable, registerCustomTableClass, unregisterCustomTableClass
from fontTools.ttLib.standardGlyphOrder import standardGlyphOrder
from fontTools.ttLib.tables.DefaultTable import DefaultTable from fontTools.ttLib.tables.DefaultTable import DefaultTable
from fontTools.ttLib.tables._c_m_a_p import CmapSubtable from fontTools.ttLib.tables._c_m_a_p import CmapSubtable
import pytest import pytest
@ -143,6 +144,13 @@ def test_setGlyphOrder_also_updates_glyf_glyphOrder():
assert font["glyf"].glyphOrder == new_order assert font["glyf"].glyphOrder == new_order
def test_getGlyphOrder_not_true_post_format_1():
# https://github.com/fonttools/fonttools/issues/2736
font = TTFont(os.path.join(DATA_DIR, "bogus_post_format_1.ttf"))
hmtx = font["hmtx"]
assert len(hmtx.metrics) > len(standardGlyphOrder)
@pytest.mark.parametrize("lazy", [None, True, False]) @pytest.mark.parametrize("lazy", [None, True, False])
def test_ensureDecompiled(lazy): def test_ensureDecompiled(lazy):
# test that no matter the lazy value, ensureDecompiled decompiles all tables # test that no matter the lazy value, ensureDecompiled decompiles all tables