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 <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
This commit is contained in:
Nigel Tao 2022-08-19 16:01:33 +10:00 committed by Gopher Robot
parent a1c9783ca1
commit 63e129ba1c

View File

@ -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
}