[cffLib] Fix for #1451 (#1456)

* a charstring is not guaranteed to end in an operator, so the final bytecodes 11 and 14 can be part of an encoded numeric value; so remove 'return' or 'endchar' at the program level instead of bytescode
* move non-CFF2 test+error to elif clause of earlier isCFF2 test
Fixes the remaining issue from #1451
This commit is contained in:
Just van Rossum 2019-01-17 16:01:15 +01:00 committed by GitHub
parent 2c204ef81b
commit 176f2e8244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -983,6 +983,16 @@ class T2CharString(object):
return return
opcodes = self.opcodes opcodes = self.opcodes
program = self.program program = self.program
if isCFF2:
# If present, remove return and endchar operators.
if program and program[-1] in ("return", "endchar"):
program = program[:-1]
elif program and not isinstance(program[-1], basestring):
raise CharStringCompileError(
"T2CharString or Subr has items on the stack after last operator."
)
bytecode = [] bytecode = []
encodeInt = self.getIntEncoder() encodeInt = self.getIntEncoder()
encodeFixed = self.getFixedEncoder() encodeFixed = self.getFixedEncoder()
@ -1005,10 +1015,6 @@ class T2CharString(object):
bytecode.append(encodeFixed(token)) bytecode.append(encodeFixed(token))
else: else:
assert 0, "unsupported type: %s" % type(token) assert 0, "unsupported type: %s" % type(token)
if not isCFF2 and program and not isinstance(program[-1], basestring):
raise CharStringCompileError(
"T2CharString or Subr has items on the stack after last operator."
)
try: try:
bytecode = bytesjoin(bytecode) bytecode = bytesjoin(bytecode)
except TypeError: except TypeError:
@ -1016,11 +1022,6 @@ class T2CharString(object):
raise raise
self.setBytecode(bytecode) self.setBytecode(bytecode)
if isCFF2:
# If present, remove return and endchar operators.
if self.bytecode and (byteord(self.bytecode[-1]) in (11, 14)):
self.bytecode = self.bytecode[:-1]
def needsDecompilation(self): def needsDecompilation(self):
return self.bytecode is not None return self.bytecode is not None