image/png: fix interlaced palette out-of-bounds
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 <58ae08b3356928ff9c67562b4719487d54fe8348@golang.org>
Reviewed-by: Andrew Gerrand <395a7d33bec8475c9b83b7d440f141bcbd994aa5@golang.org>

golang/go,CAFxX/go,CAFxX/go,cloudflare/go,cloudflare/go,CAFxX/go,cloudflare/go,nawawi/go,cloudflare/go,cloudflare/go,CAFxX/go,nawawi/go,cloudflare/go,nawawi/go,cloudflare/go,nawawi/go,golang/go,CAFxX/go,nawawi/go,CAFxX/go,golang/go,nawawi/go,golang/go,golang/go,golang/go,CAFxX/go,golang/go,golang/go,nawawi/go,CAFxX/go,nawawi/go,cloudflare/go