From 60554bdab22b251c177d0ada8512cfd43ca39192 Mon Sep 17 00:00:00 2001 From: Mat Geist Date: Sat, 23 Jan 2016 21:27:15 -0800 Subject: [PATCH] remove hardcoded offset --- truetype/truetype.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/truetype/truetype.go b/truetype/truetype.go index 75cb733..8d040c7 100644 --- a/truetype/truetype.go +++ b/truetype/truetype.go @@ -574,14 +574,15 @@ func parse(ttf []byte, offset int) (font *Font, err error) { return } n, offset := int(u16(ttf, offset)), offset+2 - if len(ttf) < 16*n+12 { + offset = offset + 2*3 // skip 3 short fields + if len(ttf) < 16*n+offset { err = FormatError("TTF data is too short") return } f := new(Font) // Assign the table slices. for i := 0; i < n; i++ { - x := 16*i + 12 + x := 16*i + offset switch string(ttf[x : x+4]) { case "cmap": f.cmap, err = readTable(ttf, ttf[x+8:x+16])