galdor / go-thumbhash

A Go implementation of the Thumbhash image placeholder generation algorithm.
ISC License
76 stars 2 forks source link

Panic when passing a specific gif #4

Open aymericbeaumet opened 6 months ago

aymericbeaumet commented 6 months ago

I've been playing with the latest version of go-thumbhash. I've found one specific image that makes the library panic. This image is a gif, we can't reproduce this consistenly as this library was able to process other gifs. Does this library supports gifs? It is unclear from the readme which image types are supported.

Minimal repro

$ go run . ~/Downloads/blob.gif
panic: runtime error: index out of range [889171] with length 889168

goroutine 1 [running]:
github.com/galdor/go-thumbhash.EncodeImage({0x10463d5f8, 0x1400007e240})
        /Users/aymericbeaumet/go/pkg/mod/github.com/galdor/go-thumbhash@v1.0.0/thumbhash.go:36 +0x61c
main.main()
        /Users/aymericbeaumet/Workspace/aymericbeaumet/thumbhash-panic/main.go:25 +0x68
exit status 2
package main

import (
    "image"
    _ "image/gif"  // add gif support
    _ "image/jpeg" // add jpeg support
    _ "image/png"  // add png support
    "os"

    "github.com/galdor/go-thumbhash"
)

func main() {
    reader, err := os.Open(os.Args[1])
    if err != nil {
        panic(err)
    }

    var img image.Image
    img, _, err = image.Decode(reader)
    if err != nil {
        panic(err)
    }

    _ = thumbhash.EncodeImage(img) // panics
}
galdor commented 6 months ago

Can you reproduce that with master?

aymericbeaumet commented 6 months ago

Using the latest master fixed the issue (command below) thank you! Would you recommend using master instead of v1.0.0, if so would this justify bumping a minor version?

go get github.com/galdor/go-thumbhash@5f40e920ff450b03da9e7a9875a452806fa89fe0