Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1826bb

Browse files
committed
Fix two crashes on slightly broken font files
The zeros at the end are not needed by our implementation so don't crash if there are too few. Always pass an even number of bytes to unhexlify.
1 parent b81313f commit a1826bb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/matplotlib/type1font.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ def _split(self, data):
128128
zeros -= 1
129129
idx -= 1
130130
if zeros:
131-
raise RuntimeError('Insufficiently many zeros in Type 1 font')
131+
# this may have been a problem on old implementations that
132+
# used the zeros as necessary padding
133+
logging.info('Insufficiently many zeros in Type 1 font')
132134

133135
# Convert encrypted part to binary (if we read a pfb file, we may end
134136
# up converting binary to hexadecimal to binary again; but if we read
135137
# a pfa file, this part is already in hex, and I am not quite sure if
136138
# even the pfb format guarantees that it will be in binary).
137-
binary = binascii.unhexlify(data[len1:idx+1])
139+
idx1 = len1 + ((idx - len1 + 2) & ~1) # ensure an even number of bytes
140+
binary = binascii.unhexlify(data[len1:idx1])
138141

139142
return data[:len1], binary, data[idx+1:]
140143

0 commit comments

Comments
 (0)