golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

image/gif: Decode returns an image with empty palette

dvyukov opened this issue · comments

The following program crashes with the panic:

package main

import (
    "bytes"
    "image/gif"
)

func main() {
    data := []byte("GIF89a000\x00000,00\x00\x00\x00\x000\x000\x02\b\r0000000\x00;")
    img, err := gif.Decode(bytes.NewReader(data))
    if err != nil {
        panic(err)
    }
    var w bytes.Buffer
    err = gif.Encode(&w, img, nil)
    if err != nil {
        panic(err)
    }
    _, err = gif.Decode(&w)
    if err != nil {
        panic(err)
    }
}
panic: gif: cannot encode image block with empty palette

goroutine 1 [running]:
main.main()
    gif.go:17 +0x219

Decode should not return an image with empty palette, it should return an error instead.

go version devel +b0532a9 Mon Jun 8 05:13:15 2015 +0000 linux/amd64

CL https://golang.org/cl/11064 mentions this issue.