From: Nigel Tao Date: Fri, 19 Aug 2022 06:01:33 +0000 (+1000) Subject: image/png: allow both PLTE and tRNS chunks for TrueColor X-Git-Tag: go1.20rc1~1368 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=63e129ba1c458db23f0752d106ed088a2cf38360;p=gostls13.git image/png: allow both PLTE and tRNS chunks for TrueColor Prior to this commit, png.Decode would allow TrueColor PNG images that have one but not both of PLTE and tRNS chunks. Fixes #54142 Change-Id: I259c1fff86a0aa5640dbadf7ad834e05fbd1430c Reviewed-on: https://go-review.googlesource.com/c/go/+/424916 TryBot-Result: Gopher Robot Auto-Submit: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) --- diff --git a/src/image/png/reader.go b/src/image/png/reader.go index b608bec2ef..3a717344c2 100644 --- a/src/image/png/reader.go +++ b/src/image/png/reader.go @@ -51,6 +51,10 @@ func cbPaletted(cb int) bool { return cbP1 <= cb && cb <= cbP8 } +func cbTrueColor(cb int) bool { + return cb == cbTC8 || cb == cbTC16 +} + // Filter type, as per the PNG spec. const ( ftNone = 0 @@ -898,6 +902,10 @@ func (d *decoder) parseChunk(configOnly bool) error { if d.stage != dsSeenPLTE { return chunkOrderError } + } else if cbTrueColor(d.cb) { + if d.stage != dsSeenIHDR && d.stage != dsSeenPLTE { + return chunkOrderError + } } else if d.stage != dsSeenIHDR { return chunkOrderError }