From d9be45aaf7452cc30c0ceb1b1bf7efe1d17b7c87 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 8 Dec 2016 17:47:10 +1100 Subject: [PATCH] Don't crash when a glyph has no contours. --- truetype/glyph.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/truetype/glyph.go b/truetype/glyph.go index c2935a5..6157ad8 100644 --- a/truetype/glyph.go +++ b/truetype/glyph.go @@ -209,6 +209,7 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error g.addPhantomsAndScale(len(g.Points), len(g.Points), true, true) copy(g.phantomPoints[:], g.Points[len(g.Points)-4:]) g.Points = g.Points[:len(g.Points)-4] + // TODO: also trim g.InFontUnits and g.Unhinted? return nil } @@ -282,6 +283,10 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { program = glyf[offset : offset+instrLen] offset += instrLen + if ne == 0 { + return program + } + np0 := len(g.Points) np1 := np0 + int(g.Ends[len(g.Ends)-1])