Catch an error unpack might throw instead of checking the length before
parent
ec8530f6cf
commit
fcd3e6ce00
|
@ -383,16 +383,16 @@ class TrueTypeFont(object):
|
|||
self.fp = fp
|
||||
self.tables = {}
|
||||
self.fonttype = fp.read(4)
|
||||
data_str = fp.read(8)
|
||||
if len(data_str) != 8:
|
||||
return
|
||||
(ntables, _1, _2, _3) = struct.unpack('>HHHH', data_str)
|
||||
try:
|
||||
(ntables, _1, _2, _3) = struct.unpack('>HHHH', fp.read(8))
|
||||
for _ in range(ntables):
|
||||
data_str = fp.read(16)
|
||||
if len(data_str) != 16:
|
||||
return
|
||||
(name, tsum, offset, length) = struct.unpack('>4sLLL', data_str)
|
||||
(name, tsum, offset, length) = struct.unpack('>4sLLL', fp.read(16))
|
||||
self.tables[name] = (offset, length)
|
||||
except struct.error:
|
||||
# Do not fail if there are not enough bytes to read. Even for
|
||||
# corrupted PDFs we would like to get as much information as
|
||||
# possible, so continue.
|
||||
pass
|
||||
return
|
||||
|
||||
def create_unicode_map(self):
|
||||
|
|
Loading…
Reference in New Issue