8000 Fixes #1675 - T1 eexec end finding spec compliance by baileyparker · Pull Request #1676 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes #1675 - T1 eexec end finding spec compliance #1676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.py text

# Font files are binary (so that autocrlf doesn't muck with them)
*.lwfn binary
*.pfa binary
*.pfb binary
9 changes: 6 additions & 3 deletions Lib/fontTools/t1Lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def writeOther(path, data, dohex=False):
# decryption tools

EEXECBEGIN = b"currentfile eexec"
EEXECEND = b'0' * 64
# The spec allows for 512 ASCII zeros interrupted by arbitrary whitespace to
# follow eexec
EEXECEND = re.compile(b'(0[ \t\r\n]*){512}', flags=re.M)
EEXECINTERNALEND = b"currentfile closefile"
EEXECBEGINMARKER = b"%-- eexec start\r"
EEXECENDMARKER = b"%-- eexec end\r"
Expand Down Expand Up @@ -312,9 +314,10 @@ def findEncryptedChunks(data):
if eBegin < 0:
break
eBegin = eBegin + len(EEXECBEGIN) + 1
eEnd = data.find(EEXECEND, eBegin)
if eEnd < 0:
endMatch = EEXECEND.search(data, eBegin)
if endMatch is None:
raise T1Error("can't find end of eexec part")
eEnd = endMatch.start()
cypherText = data[eBegin:eEnd + 2]
if isHex(cypherText[:4]):
cypherText = deHexString(cypherText)
Expand Down
63 changes: 63 additions & 0 deletions Tests/t1Lib/data/TestT1-weird-zeros.pfa

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Tests/t1Lib/t1Lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
LWFN = os.path.join(DATADIR, 'TestT1-Regular.lwfn')
PFA = os.path.join(DATADIR, 'TestT1-Regular.pfa')
PFB = os.path.join(DATADIR, 'TestT1-Regular.pfb')
WEIRD_ZEROS = os.path.join(DATADIR, 'TestT1-weird-zeros.pfa')


class FindEncryptedChunksTest(unittest.TestCase):
Expand All @@ -28,6 +29,14 @@ def test_findEncryptedChunks(self):
self.assertTrue(chunks[1][0])
self.assertFalse(chunks[2][0])

def test_findEncryptedChunks_weird_zeros(self):
with open(WEIRD_ZEROS, 'rb') as f:
data = f.read()

# Just assert that this doesn't raise any exception for not finding the
# end of eexec
t1Lib.findEncryptedChunks(data)


class DecryptType1Test(unittest.TestCase):

Expand Down
0