]> Cypherpunks.ru repositories - gostls13.git/commit
image/png: fix interlaced palette out-of-bounds
authorNigel Tao <nigeltao@golang.org>
Thu, 7 Oct 2021 23:33:47 +0000 (10:33 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 8 Oct 2021 01:18:01 +0000 (01:18 +0000)
commit8c4ea3140e7c79d828fe7683a3dfe3474a9938fb
treefd94e9048861b6f0472898429464166aa14b9a6e
parent78d749fbe978bf6eac9c5e11aa4641dc126c9128
image/png: fix interlaced palette out-of-bounds

PNG images can be paletted, where each pixel value (a uint8) indexes a
slice of colors. In terms of wire format, the PLTE chunk explicitly
contains the palette length. However, in practice, some arguably
malformed images contain pixel values greater than or equal to the
explicit PLTE length.

Go's image/png decoder accomodates such images by lengthening the
decoded image's palette if the implicit maximum is larger than the
explicit maximum. This was already done, prior to this commit, by the
"if len(paletted.Palette) <= int(idx)" lines in decoder.readImagePass.

Separately, PNG images can also be interlaced, where the final image is
the result of merging multiple partial images, also called passes. Prior
to this commit, we applied the palette lengthening to the pass images
but not the final image. This commit fixes that.

Fixes #48612

Change-Id: I77606538cc9a504fbd726071756ebcd10c9da73f
Reviewed-on: https://go-review.googlesource.com/c/go/+/354709
Trust: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/image/png/reader.go