Skip to content

Commit

Permalink
image/png: reject zero-width and zero-height images.
Browse files Browse the repository at this point in the history
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 <r@golang.org>
  • Loading branch information
nigeltao committed Sep 9, 2015
1 parent e5d9caf commit 0cf7331
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/image/png/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 0cf7331

Please sign in to comment.