]> Cypherpunks.ru repositories - gostls13.git/commitdiff
image/gif: avoid decoding past the first frame in decode()
authorChris Gillis <gillisct@gmail.com>
Fri, 18 Jun 2021 02:14:28 +0000 (02:14 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 22 Aug 2022 15:51:31 +0000 (15:51 +0000)
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

Change-Id: I0c3c11f9c11cd487b6c365e9a8b98e617d555db0
GitHub-Last-Rev: 03ebc8ee7bb19ee80c62d0c935b783d7bc75c2e9
GitHub-Pull-Request: golang/go#46813
Reviewed-on: https://go-review.googlesource.com/c/go/+/329329
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Paul Tyng <paul@paultyng.net>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
src/image/gif/reader.go
src/image/gif/reader_test.go

index 9e8268c86f3c018af93723a748a258b8c13870da..0867b1029567533182b3a95c3f7344c14b0c42d3 100644 (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")
index 5eec5ecb4a6889e8a25abb2c4cadc38c97e31f3e..a7f943adeb76ea9c125a0a40fc9ffd0349c98105 100644 (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
                }