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

Closed
artyom opened this issue Oct 19, 2016 · 1 comment
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@artyom
Copy link
Member

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)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/tmp/gopath:/Users/artyom/gopath"
GORACE=""
GOROOT="/Users/artyom/Library/go"
GOTOOLDIR="/Users/artyom/Library/go/pkg/tool/darwin_amd64"
CC="clang"
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"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

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

  1. Save linked original png file or its attached copy as /tmp/bad.png.
  2. Save and run https://play.golang.org/p/7KawpAoMqX

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
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 21, 2016
@gopherbot
Copy link

CL https://golang.org/cl/32139 mentions this issue.

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants