Skip to content

image/png: Add options to tolerate invalid checksums in ancillary chunks #43382

@stanhu

Description

@stanhu

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

$ go version
go version go1.15.6 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/stanhu/Library/Caches/go-build"
GOENV="/Users/stanhu/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/stanhu/.gvm/pkgsets/go1.15.6/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/stanhu/.gvm/pkgsets/go1.15.6/global"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/Users/stanhu/.gvm/gos/go1.15.6"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/stanhu/.gvm/gos/go1.15.6/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/stanhu/gdk-ee/gitlab-workhorse/go.mod"
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/6v/0wvd8sg951l59wy4242m3thh0000gn/T/go-build329049724=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Decoding the attached image that has valid data checksums but an invalid ICCP checksum fails a decode entirely.

openconnect2

Most image programs ignore the invalid ICC profile, but calling image.Decode fails to load this image:

decode: png: invalid format: invalid checksum

pngcheck confirms there is an invalid checksum in the iCCP chunk:

$ pngcheck -v /tmp/openconnect2.png
File: /tmp/openconnect2.png (67451 bytes)
  chunk IHDR at offset 0x0000c, length 13
    400 x 400 image, 32-bit RGB+alpha, non-interlaced
  chunk zTXt at offset 0x00025, length 13615, keyword: Raw profile type exif
  chunk iCCP at offset 0x03560, length 389
    profile name = ICC PROFILE, compression method = 0 (deflate)
    compressed profile = 376 bytes
  CRC error in chunk iCCP (computed f1449d51, expected c8439de9)
ERRORS DETECTED in /tmp/openconnect2.png

Since the ICC profile isn't absolutely necessary to render a PNG, we ought to be able to detect this error but not fail outright.

This is similar to #10447 and relates to #27830.

What did you expect to see?

The image decoded but the ICC profile skipped.

What did you see instead?

A hard failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions