Font Bakery with multithreading enabled in Python 3.12 sometimes produces errors for fonts with 'CFF ' tables when running checks that parse the glyphs’ charstrings. The errors happen frequently but not every time. I don’t know why it only seems to happen in Python 3.12.
The problem is that SimpleT2Decompiler.execute in fontTools is not thread-safe. The decompiler keeps track of the current index in the charstring. A charstring has two representations, bytecode and decompiled, which are not the same length. A SimpleT2Decompiler might use a bytecode-oriented index to index into the decompiled charstring if another thread happens to decompile it concurrently, thereby effectively skipping ahead in the charstring by an unpredictable amount.
Expected behavior
Font Bakery’s checks should not cause errors in other checks when multithreading is enabled.
A solution could be to decompile all the charstrings eagerly before anything starts indexing into them, similar to #4683. However, I don’t know if the proper fix belongs in fontTools or Font Bakery.
Observed behavior
Font Bakery with multithreading enabled in Python 3.12 sometimes produces errors for fonts with 'CFF ' tables when running checks that parse the glyphs’ charstrings. The errors happen frequently but not every time. I don’t know why it only seems to happen in Python 3.12.
The problem is that
SimpleT2Decompiler.execute
in fontTools is not thread-safe. The decompiler keeps track of the current index in the charstring. A charstring has two representations, bytecode and decompiled, which are not the same length. ASimpleT2Decompiler
might use a bytecode-oriented index to index into the decompiled charstring if another thread happens to decompile it concurrently, thereby effectively skipping ahead in the charstring by an unpredictable amount.Expected behavior
Font Bakery’s checks should not cause errors in other checks when multithreading is enabled.
A solution could be to decompile all the charstrings eagerly before anything starts indexing into them, similar to #4683. However, I don’t know if the proper fix belongs in fontTools or Font Bakery.
Resources and steps needed to reproduce