From: Nigel Tao Date: Thu, 27 Oct 2016 02:36:48 +0000 (+1100) Subject: image/png: allow tRNS chunk without a PLTE chunk. X-Git-Tag: go1.8beta1~570 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=de4b06559119eac499906aaa4d42046b3beed52d;p=gostls13.git image/png: allow tRNS chunk without a PLTE chunk. While https://www.w3.org/TR/PNG/#5ChunkOrdering says that tRNS's ordering constraint is "After PLTE; before IDAT", it is legal for a tRNS chunk to occur without a PLTE chunk at all, for greyscale and truecolor transparency as opposed to palette-based transparency. See https://www.w3.org/TR/PNG/#11transinfo Fixes #17511. Change-Id: I047b0b01d78a1cda65e00eeac229bb972cda431d Reviewed-on: https://go-review.googlesource.com/32139 Reviewed-by: Rob Pike --- diff --git a/src/image/png/reader.go b/src/image/png/reader.go index 2dd5ed8073..44214eda29 100644 --- a/src/image/png/reader.go +++ b/src/image/png/reader.go @@ -709,7 +709,11 @@ func (d *decoder) parseChunk() error { d.stage = dsSeenPLTE return d.parsePLTE(length) case "tRNS": - if d.stage != dsSeenPLTE { + if cbPaletted(d.cb) { + if d.stage != dsSeenPLTE { + return chunkOrderError + } + } else if d.stage != dsSeenIHDR { return chunkOrderError } d.stage = dsSeentRNS