From 63e129ba1c458db23f0752d106ed088a2cf38360 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 19 Aug 2022 16:01:33 +1000 Subject: [PATCH] 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) --- src/image/png/reader.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/image/png/reader.go b/src/image/png/reader.go index b608bec2ef0..3a717344c27 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 }