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: panic on Encode for CCITTGroup4 compression #35259

Closed
samuel opened this issue Oct 31, 2019 · 1 comment
Closed

x/image/tiff: panic on Encode for CCITTGroup4 compression #35259

samuel opened this issue Oct 31, 2019 · 1 comment

Comments

@samuel
Copy link

samuel commented Oct 31, 2019

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

go version go1.13.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes, latest master of x/image

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

Darwin/amd64

What did you do?

	fo, err := os.Create("output.tiff")
	if err != nil {
		log.Fatal(err)
	}
	defer fo.Close()
	if err := tiff.Encode(fo, img, &tiff.Options{
		Compression: tiff.CCITTGroup4,
	}); err != nil {
		log.Fatal(err)
	}

What did you expect to see?

TIFF written using CCITTGroup4 compression (or optionally an error if compression isn't support for encode).

What did you see instead?

Panic

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

goroutine 1 [running]:
golang.org/x/image/tiff.writePix(0x0, 0x0, 0xc0000dc000, 0x212c830, 0x212c830, 0xdb4, 0x26bc, 0x26bc, 0xc0000c7b88, 0x100be08)
	/Users/samuel/go/src/golang.org/x/image/tiff/writer.go:211 +0x4f
golang.org/x/image/tiff.encodeRGBA(0x0, 0x0, 0xc0000dc000, 0x212c830, 0x212c830, 0x9af, 0xdb4, 0x26bc, 0xc0000c7c00, 0x1029da1, ...)
	/Users/samuel/go/src/golang.org/x/image/tiff/writer.go:108 +0x2fb
golang.org/x/image/tiff.Encode(0x114db80, 0xc00000e080, 0x114eb80, 0xc002230000, 0xc0000c7e50, 0x1, 0x1)
	/Users/samuel/go/src/golang.org/x/image/tiff/writer.go:378 +0x1391
main.main()
	/Users/samuel/go/src/github.com/samuel/batchimg/main.go:49 +0x661

When Encode sets up the output writer dst for the selected compression it only looks for cNone and cDeflate. Any other choice leads to dst being left nil which means when the encode* functions to to write to it they panic. https://github.com/golang/image/blob/master/tiff/writer.go#L317

Seems best if Encode returned an error in the case of an unsupported compression.

@gopherbot gopherbot added this to the Unreleased milestone Oct 31, 2019
@samuel
Copy link
Author

samuel commented Oct 31, 2019

I see that there's a CL (https://go-review.googlesource.com/c/image/+/183224) for adding encoding support in image/ccitt which I assume will also tie into image/tiff so I'll close this since it'll be solved by that. Sorry for the noise.

@samuel samuel closed this as completed Oct 31, 2019
@golang golang locked and limited conversation to collaborators Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants