mirror of
https://github.com/golang/go
synced 2024-11-17 06:14:51 -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
Change-Id: I0c3c11f9c11cd487b6c365e9a8b98e617d555db0
GitHub-Last-Rev: 03ebc8ee7b
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>
This commit is contained in:
parent
db3e915af2
commit
b4c124af1e
@ -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")
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user