go: image/gif: generated image cannot be opened in xv and crashes OmniWeb 3.x web browser

What version of Go are you using (go version)?

$ go version
go version go1.12.5 linux/amd64

Does this issue reproduce with the latest release?

yes, any release

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/tenox/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/tenox/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build197159774=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create a simple gif image:

package main

import (
	"image"
	"image/color"
	"image/gif"
	"os"
	"fmt"
)

func main() {
	g, _ := os.Create("go.gif")
	defer g.Close()
	p := []color.Color{color.White, color.Black}
	r := image.Rect(0,0,100,100)
	i := image.NewPaletted(r, p)
	for x:=20; x<40; x++ {
		for y:=20; y<40; y++ {
			fmt.Printf("%d %d", x, y)
			i.SetColorIndex(x,y, 1)
		}
	}
	gif.Encode(g, i, nil)
}

What did you expect to see?

Expected to open in older image viewers, editors and browsers.

What did you see instead?

A number of old browsers, image viewers and editors report generated gif image as corrupted or display it mangled. For example xv image viewer, https://en.wikipedia.org/wiki/Xv_(software) says the file is turncated. OmniWeb browser (v2.x and v3.x) crashes. Most graphical software on SGI IRIX reports it corrupted.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (6 by maintainers)

Most upvoted comments

@mntn-xyz thanks for the excellent and thorough debugging. I have sent out a fix for review.

I expect it to release in Go 1.18.

If you must have it sooner, you can always fork the compress/lzw and image/gif packages from the standard library, as a temporary measure.