webp: fix panic in case of invalid chunkID

At the time of decoding webp file, if chunkID is not one of
{'ALPH', 'VP8', 'VP8L', 'VP8X'} return errInvalidFormat

Fixes golang/go#10384

Change-Id: I167909b5ddef174d161f806297a08fac6aabcf19
Reviewed-on: https://go-review.googlesource.com/9839
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
Aamir Khan 2015-05-10 04:02:24 +09:00 committed by Nigel Tao
parent f28211f6e1
commit 25eff15cb8
2 changed files with 6 additions and 4 deletions

View File

@ -136,11 +136,10 @@ func (z *Reader) Next() (chunkID FourCC, chunkLen uint32, chunkData io.Reader, e
return FourCC{}, 0, nil, z.err return FourCC{}, 0, nil, z.err
} }
chunkID = FourCC{z.buf[0], z.buf[1], z.buf[2], z.buf[3]} chunkID = FourCC{z.buf[0], z.buf[1], z.buf[2], z.buf[3]}
chunkLen = u32(z.buf[4:]) z.chunkLen = u32(z.buf[4:])
z.chunkLen = chunkLen z.padded = z.chunkLen&1 == 1
z.padded = chunkLen&1 == 1
z.chunkReader = &chunkReader{z} z.chunkReader = &chunkReader{z}
return chunkID, chunkLen, z.chunkReader, nil return chunkID, z.chunkLen, z.chunkReader, nil
} }
type chunkReader struct { type chunkReader struct {

View File

@ -144,6 +144,9 @@ func decode(r io.Reader, configOnly bool) (image.Image, image.Config, error) {
}, nil }, nil
} }
wantAlpha = true wantAlpha = true
default:
return nil, image.Config{}, errInvalidFormat
} }
} }
} }