golang/go

image/gif: Disposal is corrupted after round trip

dvyukov opened this issue · 1 comments

The following program:

package main

import (
    "bytes"
    "fmt"
    "image/gif"
)

func main() {
    data := []byte("GIF87au\x010\x00\xe800000000!" +
        "\xf9000000,0\x000\x000\x00\x00\x000\x02\b\r" +
        "0000000\x00!\xf90\x00\x00\x0000,0\x000" +
        "\x000\x00\x00\x000\x02\b\r0000000\x00;")
    img, err := gif.DecodeAll(bytes.NewReader(data))
    if err != nil {
        return
    }
    w := new(bytes.Buffer)
    err = gif.EncodeAll(w, img)
    if err != nil {
        panic(err)
    }
    img1, err := gif.DecodeAll(w)
    if err != nil {
        panic(err)
    }
    fmt.Printf("LoopCount: %v -> %v\n", img.Disposal, img1.Disposal)
}

prints:

LoopCount: [4 0] -> [4 4]

Disposal must be preserved after Encode/Decode.

go version devel +514014c Thu Jun 18 15:54:35 2015 +0200 linux/amd64

gif.DecodeAll now returns an error with this input: https://play.golang.org/p/ayU0ZmlaCwk

invalid graphic control extension block size: 48