[ttLib] fix UnboundLocalError for empty loca/glyph tables (#1680)
* Rename last to pos, and next to nextPos * make sure nextPos is initialized, to avoid UnboundLocalError on an empty glyf table, partially addressing #684
This commit is contained in:
parent
4c86ca608f
commit
5d6f08fd95
@ -55,7 +55,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
|
||||
|
||||
def decompile(self, data, ttFont):
|
||||
loca = ttFont['loca']
|
||||
last = int(loca[0])
|
||||
pos = int(loca[0])
|
||||
nextPos = 0
|
||||
noname = 0
|
||||
self.glyphs = {}
|
||||
self.glyphOrder = glyphOrder = ttFont.getGlyphOrder()
|
||||
@ -65,17 +66,17 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
|
||||
except IndexError:
|
||||
noname = noname + 1
|
||||
glyphName = 'ttxautoglyph%s' % i
|
||||
next = int(loca[i+1])
|
||||
glyphdata = data[last:next]
|
||||
if len(glyphdata) != (next - last):
|
||||
nextPos = int(loca[i+1])
|
||||
glyphdata = data[pos:nextPos]
|
||||
if len(glyphdata) != (nextPos - pos):
|
||||
raise ttLib.TTLibError("not enough 'glyf' table data")
|
||||
glyph = Glyph(glyphdata)
|
||||
self.glyphs[glyphName] = glyph
|
||||
last = next
|
||||
if len(data) - next >= 4:
|
||||
pos = nextPos
|
||||
if len(data) - nextPos >= 4:
|
||||
log.warning(
|
||||
"too much 'glyf' table data: expected %d, received %d bytes",
|
||||
next, len(data))
|
||||
nextPos, len(data))
|
||||
if noname:
|
||||
log.warning('%s glyphs have no name', noname)
|
||||
if ttFont.lazy is False: # Be lazy for None and True
|
||||
|
Loading…
x
Reference in New Issue
Block a user