You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Python TTF parser fails to parse some TTF files (e.g. Roboto).
Steps to reproduce:
(ttf_venv) user@user-VirtualBox:~/temp$ python3 -m pip install kaitaistructCollecting kaitaistruct Downloading kaitaistruct-0.10-py2.py3-none-any.whl (7.0 kB)Installing collected packages: kaitaistructSuccessfully installed kaitaistruct-0.10(ttf_venv) user@user-VirtualBox:~/temp$ wget https://github.com/google/fonts/raw/d27d4149a40a9db16637f493f039255f5cb52d1f/ofl/roboto/Roboto%5Bwdth,wght%5D.ttf -q -O roboto.ttf(ttf_venv) user@user-VirtualBox:~/temp$ wget http://formats.kaitai.io/ttf/src/python/ttf.py -q(ttf_venv) user@user-VirtualBox:~/temp$ pythonPython 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> from ttf import Ttf>>> data = Ttf.from_file("roboto.ttf")>>> data._read()Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user/temp/ttf.py", line 28, in _read self.directory_table.append(Ttf.DirTableEntry(self._io, self, self._root)) File "/home/user/temp/ttf.py", line 347, in __init__ self._read() File "/home/user/temp/ttf.py", line 350, in _read self.tag = (self._io.read_bytes(4)).decode(u"ascii")UnicodeDecodeError: 'ascii' codec can't decode byte 0xf5 in position 3: ordinal not in range(128)
For what it's worth, the problem can be worked around by modifying the decode()s to ignore errors:
(ttf_venv) user@user-VirtualBox:~/temp$ sed -i -e 's/decode(u"\([^"]*\)")/decode(u"\1", errors="ignore")/g' ttf.py(ttf_venv) user@user-VirtualBox:~/temp$ pythonPython 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> from ttf import Ttf>>> data = Ttf.from_file("roboto.ttf")>>> data._read()>>> data<ttf.Ttf object at 0x7f68577cc460>
I'm not sure if this can be considered a real fix though.
The Python TTF parser fails to parse some TTF files (e.g. Roboto).
Steps to reproduce:
For what it's worth, the problem can be worked around by modifying the
decode()
s to ignore errors:I'm not sure if this can be considered a real fix though.
Originally found as part of a pytai issue.
The text was updated successfully, but these errors were encountered: