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

image/png: decoding images with truecolor transparency returns wrong error #17511

artyom opened this issue Oct 19, 2016 · 1 comment

image/png: decoding images with truecolor transparency returns wrong error #17511

artyom opened this issue Oct 19, 2016 · 1 comment


Copy link

@artyom artyom commented Oct 19, 2016

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.1 darwin/amd64

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

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lb/3rk8rqs53czgb4v35w_342xc0000gn/T/go-build425021710=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on is best.

  1. Save linked original png file or its attached copy as /tmp/bad.png.
  2. Save and run

What did you expect to see?

Either no error message or png.UnsupportedError text.

What did you see instead?

png: invalid format: chunk out of order

Initially I thought that file was incorrect but that doesn't seem to be the case:

$ pngcheck -v -p /tmp/bad.png 
File: /tmp/bad.png (3616 bytes)
  chunk IHDR at offset 0x0000c, length 13
    128 x 128 image, 24-bit RGB, non-interlaced
  chunk tRNS at offset 0x00025, length 6
    red = 0x00ff, green = 0x00ff, blue = 0x00ff
  chunk IDAT at offset 0x00037, length 3541
    zlib: deflated, 32K window, superfast compression
  chunk IEND at offset 0x00e18, length 0
No errors detected in /tmp/bad.png (4 chunks, 92.6% compression).

It seems to have tRNS chunk but no PLTE chunk, as it's a truecolor transparent file, which is valid per spec. Ordering seem to be valid as well.

Applying the following patch:

diff --git i/src/image/png/reader.go w/src/image/png/reader.go
index 2dd5ed8..6159323 100644
--- i/src/image/png/reader.go
+++ w/src/image/png/reader.go
@@ -709,7 +709,7 @@ func (d *decoder) parseChunk() error {
        d.stage = dsSeenPLTE
        return d.parsePLTE(length)
    case "tRNS":
-       if d.stage != dsSeenPLTE {
+       if d.stage != dsSeenPLTE && d.stage != dsSeenIHDR {
            return chunkOrderError
        d.stage = dsSeentRNS

results in error reported as png: unsupported feature: truecolor transparency which seems to be the correct message for this case.

/cc @nigeltao

@bradfitz bradfitz added this to the Go1.8Maybe milestone Oct 19, 2016
Copy link

@gopherbot gopherbot commented Oct 27, 2016

CL mentions this issue.


@gopherbot gopherbot closed this in de4b065 Oct 27, 2016
@golang golang locked and limited conversation to collaborators Oct 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants