Skip to content

ttc fonts: crash resulting from unexpected OpenType features #597

@frankrolf

Description

@frankrolf

I found this by accident – it seems that DrawBot’s warning OpenType feature 'xxxx' not available for xxx does not reliably work for ttc fonts.

I get

Traceback (most recent call last):
  File "<untitled>", line 10, in <module>
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/drawBot/context/baseContext.py", line 1277, in __init__
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/drawBot/context/baseContext.py", line 1402, in append
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/drawBot/misc.py", line 402, in wrapper
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/drawBot/context/tools/openType.py", line 65, in getFeatureTagsForFont
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otBase.py", line 890, in __getattr__
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otBase.py", line 987, in decompile
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otConverters.py", line 157, in readArray
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otConverters.py", line 603, in read
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otBase.py", line 991, in decompile
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otConverters.py", line 316, in read
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otBase.py", line 329, in readUShort
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.12/fontTools/ttLib/tables/otBase.py", line 291, in readValue
struct.error: ('unpack requires a buffer of 2 bytes', 'SettingValue', 'Setting')

to reproduce:

from fontTools.ttLib import TTCollection
from pathlib import Path

fonts = list(Path('/System/Library/Fonts/Supplemental').rglob('*.ttc'))

for font_path in fonts:
    tt_collection = TTCollection(font_path)
    for font_number, font_obj in enumerate(tt_collection.fonts):
        try:
            fs = FormattedString(
                '123',
                font=str(font_path),
                fontNumber=font_number,
                openTypeFeatures=dict(onum=True),
            )
        except Exception:
            print(f'bad font: {font_path}')
        

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions