28
28
from kaitaistruct import KaitaiStruct , KaitaiStream , BytesIO
29
29
import collections
30
30
from enum import Enum
31
+ import string
31
32
32
33
33
34
if getattr (kaitaistruct , 'API_VERSION' , (0 , 9 )) < (0 , 9 ):
@@ -276,7 +277,11 @@ def ascii_value(self):
276
277
_pos = io .pos ()
277
278
io .seek ((self ._parent .ofs_strings + self .ofs_str ))
278
279
self ._debug ['_m_ascii_value' ]['start' ] = io .pos ()
279
- self ._m_ascii_value = (io .read_bytes (self .len_str )).decode (u"ascii" )
280
+ try :
281
+ self ._m_ascii_value = (io .read_bytes (self .len_str )).decode (u"ascii" )
282
+ self ._m_ascii_value = '' .join (filter (lambda x :x in string .printable , self ._m_ascii_value ))
283
+ except UnicodeDecodeError :
284
+ self ._m_ascii_value = ''
280
285
self ._debug ['_m_ascii_value' ]['end' ] = io .pos ()
281
286
io .seek (_pos )
282
287
return getattr (self , '_m_ascii_value' , None )
@@ -290,7 +295,10 @@ def unicode_value(self):
290
295
_pos = io .pos ()
291
296
io .seek ((self ._parent .ofs_strings + self .ofs_str ))
292
297
self ._debug ['_m_unicode_value' ]['start' ] = io .pos ()
293
- self ._m_unicode_value = (io .read_bytes (self .len_str )).decode (u"utf-16be" )
298
+ try :
299
+ self ._m_unicode_value = (io .read_bytes (self .len_str )).decode (u"utf-16be" )
300
+ except UnicodeDecodeError :
301
+ self ._m_unicode_value = ''
294
302
self ._debug ['_m_unicode_value' ]['end' ] = io .pos ()
295
303
io .seek (_pos )
296
304
return getattr (self , '_m_unicode_value' , None )
@@ -1714,7 +1722,7 @@ def _read(self):
1714
1722
self .value = Ttf .Cmap .Subtable .TrimmedTableMapping (_io__raw_value , self , self ._root )
1715
1723
self .value ._read ()
1716
1724
else :
1717
- self .value = self ._io .read_bytes ((self .length - 6 ))
1725
+ self .value = self ._io .read_bytes (max (self .length - 6 , 0 ))
1718
1726
self ._debug ['value' ]['end' ] = self ._io .pos ()
1719
1727
1720
1728
class ByteEncodingTable (KaitaiStruct ):
0 commit comments