Commit 82020f86 authored by Jeff R. Allen's avatar Jeff R. Allen Committed by Nigel Tao

image/gif: return an error on missing palette

A frame that tries to use the global palette when it has
not been given should result in an error, not an image
with no palette at all.

Fixes #11150.

Change-Id: If0c3a201a0ac977eee2b7a5dc68930c0c5787f40
Reviewed-on: https://go-review.googlesource.com/11064Reviewed-by: default avatarNigel Tao <nigeltao@golang.org>
parent 682ecea9
...@@ -173,6 +173,9 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error { ...@@ -173,6 +173,9 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error {
return err return err
} }
} else { } else {
if d.globalColorTable == nil {
return errors.New("gif: no color table")
}
m.Palette = d.globalColorTable m.Palette = d.globalColorTable
} }
if d.hasTransparentIndex && int(d.transparentIndex) < len(m.Palette) { if d.hasTransparentIndex && int(d.transparentIndex) < len(m.Palette) {
......
...@@ -217,7 +217,7 @@ func TestNoPalette(t *testing.T) { ...@@ -217,7 +217,7 @@ func TestNoPalette(t *testing.T) {
b.WriteString(trailerStr) b.WriteString(trailerStr)
try(t, b.Bytes(), "gif: invalid pixel value") try(t, b.Bytes(), "gif: no color table")
} }
func TestPixelOutsidePaletteRange(t *testing.T) { func TestPixelOutsidePaletteRange(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment