From 0cf7331391ba9ceb7ae755ca9172ba90f6ac516b Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 9 Sep 2015 10:57:40 +1000 Subject: [PATCH] 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/14411 Reviewed-by: Rob Pike --- src/image/png/reader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/image/png/reader.go b/src/image/png/reader.go index bbd6f753fa..ae6b775b4e 100644 --- a/src/image/png/reader.go +++ b/src/image/png/reader.go @@ -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)) { -- 2.48.1