Merge pull request #96 from sschuberth/patch-1

TrueTypeFont: Check for enough data to unpack
pull/114/head
Tata Ganesh 2018-01-31 18:26:54 +05:30 committed by GitHub
commit 3e6cc20cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -383,10 +383,16 @@ class TrueTypeFont(object):
self.fp = fp self.fp = fp
self.tables = {} self.tables = {}
self.fonttype = fp.read(4) self.fonttype = fp.read(4)
(ntables, _1, _2, _3) = struct.unpack('>HHHH', fp.read(8)) try:
for _ in range(ntables): (ntables, _1, _2, _3) = struct.unpack('>HHHH', fp.read(8))
(name, tsum, offset, length) = struct.unpack('>4sLLL', fp.read(16)) for _ in range(ntables):
self.tables[name] = (offset, length) (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 return
def create_unicode_map(self): def create_unicode_map(self):

Binary file not shown.

View File

@ -47,11 +47,15 @@ class TestDumpPDF():
def test_7(self): def test_7(self):
run('../samples/contrib/','stamp-no') run('../samples/contrib/','stamp-no')
""" """
def test_8(self): def test_8(self):
run('../samples/contrib/','2b','-A -t xml') run('../samples/contrib/','2b','-A -t xml')
def test_9(self): def test_9(self):
run('../samples/nonfree/','175') # https://github.com/pdfminer/pdfminer.six/issues/65 run('../samples/nonfree/','175') # https://github.com/pdfminer/pdfminer.six/issues/65
def test_10(self):
run('../samples/scancode/','patchelf') # https://github.com/euske/pdfminer/issues/96
if __name__ == '__main__': if __name__ == '__main__':
nose.runmodule() nose.runmodule()