Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/image/tiff: tiff.Encode panics when using the tiff.LZW compression option #43137

Closed
YuZhangForWeb opened this issue Dec 11, 2020 · 4 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@YuZhangForWeb
Copy link

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

$ go version
go version go1.15.4 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/albert/Library/Caches/go-build"
GOENV="/Users/albert/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/albert/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/albert/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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=/var/folders/dz/tj8l83gs0558qw1kcdwswc300000gn/T/go-build127077878=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I tried to create a tiff image with the lzw compression option, example code as following

package main

import (
	"fmt"
	"golang.org/x/image/tiff"
	"image"
	"bytes"
)

func main() {
	img := image.NewGray(image.Rectangle{
		Min: image.Point{0, 0},
		Max: image.Point{1, 1},
	})
	dst := bytes.Buffer{}
	err := tiff.Encode(&dst, img, &tiff.Options{Compression: tiff.LZW})
	fmt.Println(err)
}

What did you expect to see?

it encodes the data in tiff format without error or returns an error.

What did you see instead?

it panics (it seems the tiff package does not correctly handle the LZW compression option)

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4bf26f]

goroutine 1 [running]:
golang.org/x/image/tiff.writePix(0x0, 0x0, 0xc00002c00c, 0x1, 0x1, 0x1, 0x1, 0x1, 0x10, 0x4cf880)
	/tmp/gopath140285542/pkg/mod/golang.org/x/image@v0.0.0-20201208152932-35266b937fa6/tiff/writer.go:211 +0x4f
golang.org/x/image/tiff.encodeGray(0x0, 0x0, 0xc00002c00c, 0x1, 0x1, 0x1, 0x1, 0x1, 0xc000068d00, 0x8, ...)
	/tmp/gopath140285542/pkg/mod/golang.org/x/image@v0.0.0-20201208152932-35266b937fa6/tiff/writer.go:60 +0x1f0
golang.org/x/image/tiff.Encode(0x510a80, 0xc000060180, 0x511520, 0xc000016080, 0xc000068f50, 0xc000068f78, 0x4055a5)
	/tmp/gopath140285542/pkg/mod/golang.org/x/image@v0.0.0-20201208152932-35266b937fa6/tiff/writer.go:370 +0xff9
main.main()
	/tmp/sandbox218697827/prog.go:16 +0xaf
@gopherbot gopherbot added this to the Unreleased milestone Dec 11, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 11, 2020
@toothrot
Copy link
Contributor

/cc @nigeltao

@ianlancetaylor ianlancetaylor changed the title x/image/tiff: tiff.Encode panics when using the tiff.LZW compresstion option x/image/tiff: tiff.Encode panics when using the tiff.LZW compression option Dec 11, 2020
@robertabenassi
Copy link

The same for using other kind of CompressionType (only Deflate is working, as well as the Uncompress)

@gopherbot
Copy link

Change https://golang.org/cl/380334 mentions this issue: tiff: do not crash when encodin with unsupported compression

@bsiegert
Copy link
Contributor

The Encode function only supports uncompressed and Deflated-compressed images. I just sent https://golang.org/cl/380334, which turns this into an error.

@golang golang locked and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants