1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:00:09 -07:00

image/gif: avoid decoding past the first frame in decode()

The existing decode() method offers the ability to keep just one
frame of the GIF image, however it will read and decompress all
subsequent frames regardless.

Fixes #41142
This commit is contained in:
Chris Gillis 2021-06-17 21:53:31 -04:00
parent 45f251ad6c
commit 03ebc8ee7b
2 changed files with 5 additions and 1 deletions

View File

@ -250,6 +250,10 @@ func (d *decoder) decode(r io.Reader, configOnly, keepAllFrames bool) error {
return err
}
if !keepAllFrames && len(d.image) == 1 {
return nil
}
case sTrailer:
if len(d.image) == 0 {
return fmt.Errorf("gif: missing image data")

View File

@ -379,7 +379,7 @@ func TestLoopCount(t *testing.T) {
func TestUnexpectedEOF(t *testing.T) {
for i := len(testGIF) - 1; i >= 0; i-- {
_, err := Decode(bytes.NewReader(testGIF[:i]))
_, err := DecodeAll(bytes.NewReader(testGIF[:i]))
if err == errNotEnough {
continue
}