Report error is post table version 2.0 is too small
This commit is contained in:
parent
bb5d59300c
commit
add77ca3f7
@ -87,11 +87,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
||||
indices.frombytes(data[:2*numGlyphs])
|
||||
if sys.byteorder != "big": indices.byteswap()
|
||||
data = data[2*numGlyphs:]
|
||||
|
||||
maxIndex = 0
|
||||
for i in range(numGlyphs):
|
||||
if indices[i] > maxIndex: maxIndex = indices [i]
|
||||
|
||||
maxIndex = max(indices[:numGlyphs])
|
||||
self.extraNames = extraNames = unpackPStrings(data, maxIndex-257)
|
||||
self.glyphOrder = glyphOrder = [""] * int(ttFont['maxp'].numGlyphs)
|
||||
for glyphID in range(numGlyphs):
|
||||
@ -259,17 +255,34 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
||||
self.data = readHex(content)
|
||||
|
||||
|
||||
def unpackPStrings(data, nbStrings):
|
||||
def unpackPStrings(data, n):
|
||||
# extract n Pascal strings from data.
|
||||
# if there is not enough data, use ""
|
||||
|
||||
strings = []
|
||||
index = 0
|
||||
while nbStrings > 0:
|
||||
length = byteord(data[index])
|
||||
strings.append(tostr(data[index+1:index+1+length], encoding="latin1"))
|
||||
index = index + 1 + length
|
||||
nbStrings = nbStrings - 1
|
||||
dataLen = len(data)
|
||||
|
||||
for _ in range(n):
|
||||
if (dataLen <= index):
|
||||
length = 0
|
||||
else:
|
||||
length = byteord(data[index])
|
||||
index += 1
|
||||
|
||||
if (dataLen <= index + length - 1):
|
||||
name = ""
|
||||
else:
|
||||
name = tostr(data[index:index+length], encoding="latin1")
|
||||
strings.append (name)
|
||||
index += length
|
||||
|
||||
if (index < dataLen):
|
||||
log.warning("%d extra bytes in post.stringData array", dataLen - index)
|
||||
log.warning("%d extra bytes in post.stringData array", dataLen - index)
|
||||
|
||||
elif (dataLen < index):
|
||||
log.warning("not enough data in post.stringData array")
|
||||
|
||||
return strings
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user