Commit c47f0865 authored by Nigel Tao's avatar Nigel Tao

image/png: fix crash when an alleged PNG has too much pixel data,

so that the zlib.Reader returns nil error.

Fixes #7762.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/86750044
parent dacc020c
...@@ -505,8 +505,14 @@ func (d *decoder) decode() (image.Image, error) { ...@@ -505,8 +505,14 @@ func (d *decoder) decode() (image.Image, error) {
} }
// Check for EOF, to verify the zlib checksum. // Check for EOF, to verify the zlib checksum.
n, err := r.Read(pr[:1]) n := 0
if err != io.EOF { for i := 0; n == 0 && err == nil; i++ {
if i == 100 {
return nil, io.ErrNoProgress
}
n, err = r.Read(pr[:1])
}
if err != nil && err != io.EOF {
return nil, FormatError(err.Error()) return nil, FormatError(err.Error())
} }
if n != 0 || d.idatLength != 0 { if n != 0 || d.idatLength != 0 {
......
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