git.lucas.co / go_mono
git clone https://git.lucas.co/go_mono.git

commit70e8d0d3baa9a699c3865c753cbfa8ae65bd86ce
parent99f80d0ecb
authorNigel Tao <[email protected]>
date2022-04-07 21:57
font/sfnt: fix Font.GlyphIndex nil Buffer dereference

Fixes golang/go#46948

Change-Id: Ie3a2e60cf858ebeded73686bbac3e8d8448132a8
Reviewed-on: https://go-review.googlesource.com/c/image/+/398774
Reviewed-by: Dmitri Shuralyov <[email protected]>
Run-TryBot: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Nigel Tao <[email protected]>
Auto-Submit: Nigel Tao <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <[email protected]>

 font/sfnt/cmap.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/font/sfnt/cmap.go b/font/sfnt/cmap.go
index 55b4ead..2035ea9 100644
--- a/font/sfnt/cmap.go
+++ b/font/sfnt/cmap.go
@@ -186,6 +186,9 @@ func (f *Font) makeCachedGlyphIndexFormat4(buf []byte, offset, length uint32) ([
 				if offset > indexesLength || offset+2 > indexesLength {
 					return 0, errInvalidCmapTable
 				}
+				if b == nil {
+					b = &Buffer{}
+				}
 				x, err := b.view(&f.src, int(indexesBase+offset), 2)
 				if err != nil {
 					return 0, err