8000 Fix two crashes on slightly broken font files · matplotlib/matplotlib@06845a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06845a4

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 338d494 commit 06845a4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/type1font.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import binascii
2525
import enum
2626
import itertools
27+
import logging
2728
import re
2829
import struct
2930

@@ -32,6 +33,7 @@
3233
from matplotlib.cbook import _format_approx
3334
from . import _api
3435

36+
_log = logging.getLogger(__name__)
3537

3638
# token types
3739
_TokenType = enum.Enum('_TokenType',
@@ -129,13 +131,16 @@ def _split(self, data):
129131
zeros -= 1
130132
idx -= 1
131133
if zeros:
132-
raise RuntimeError('Insufficiently many zeros in Type 1 font')
134+
# this may have been a problem on old implementations that
135+
# used the zeros as necessary padding
136+
_log.info('Insufficiently many zeros in Type 1 font')
133137

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

140145
return data[:len1], binary, data[idx+1:]
141146

0 commit comments

Comments
 (0)
0