Commit 0cf73313 authored by Nigel Tao's avatar Nigel Tao

image/png: reject zero-width and zero-height images.

http://www.w3.org/TR/PNG/#11IHDR says that "Zero is an invalid value".

This change only affects the decoder. The encoder already checks
non-positive instead of negative.

Fixes #12545.

Change-Id: Iba40e1a2f4e0eec8b2fbcd3bbdae886311434da7
Reviewed-on: https://go-review.googlesource.com/14411Reviewed-by: default avatarRob Pike <r@golang.org>
parent e5d9cafb
......@@ -154,8 +154,8 @@ func (d *decoder) parseIHDR(length uint32) error {
d.interlace = int(d.tmp[12])
w := int32(binary.BigEndian.Uint32(d.tmp[0:4]))
h := int32(binary.BigEndian.Uint32(d.tmp[4:8]))
if w < 0 || h < 0 {
return FormatError("negative dimension")
if w <= 0 || h <= 0 {
return FormatError("non-positive dimension")
}
nPixels := int64(w) * int64(h)
if nPixels != int64(int(nPixels)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment