Skip to content

Commit 63e129b

Browse files
nigeltaogopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <[email protected]>
1 parent a1c9783 commit 63e129b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/image/png/reader.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func cbPaletted(cb int) bool {
5151
return cbP1 <= cb && cb <= cbP8
5252
}
5353

54+
func cbTrueColor(cb int) bool {
55+
return cb == cbTC8 || cb == cbTC16
56+
}
57+
5458
// Filter type, as per the PNG spec.
5559
const (
5660
ftNone = 0
@@ -898,6 +902,10 @@ func (d *decoder) parseChunk(configOnly bool) error {
898902
if d.stage != dsSeenPLTE {
899903
return chunkOrderError
900904
}
905+
} else if cbTrueColor(d.cb) {
906+
if d.stage != dsSeenIHDR && d.stage != dsSeenPLTE {
907+
return chunkOrderError
908+
}
901909
} else if d.stage != dsSeenIHDR {
902910
return chunkOrderError
903911
}

0 commit comments

Comments
 (0)