Skip to content

Commit 4bba672

Browse files
andybonsnigeltao
authored andcommitted
image/gif: set default loop count to 0 when app ext. is not present
It was otherwise not being preserved across specific Decode->Encode->Decode calls. Fixes #11287 Change-Id: I40602da7fa39ec67403bed52ff403f361c6171bb Reviewed-on: https://go-review.googlesource.com/11256 Reviewed-by: Nigel Tao <nigeltao@golang.org>
1 parent f2662f2 commit 4bba672

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/image/gif/reader.go

-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ func (d *decoder) readHeaderAndScreenDescriptor() error {
271271
}
272272
}
273273
// d.tmp[12] is the Pixel Aspect Ratio, which is ignored.
274-
d.loopCount = -1
275274
return nil
276275
}
277276

src/image/gif/reader_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,24 @@ func TestPixelOutsidePaletteRange(t *testing.T) {
253253
try(t, b.Bytes(), want)
254254
}
255255
}
256+
257+
func TestLoopCount(t *testing.T) {
258+
data := []byte("GIF89a000\x00000,0\x00\x00\x00\n\x00" +
259+
"\n\x00\x80000000\x02\b\xf01u\xb9\xfdal\x05\x00;")
260+
img, err := DecodeAll(bytes.NewReader(data))
261+
if err != nil {
262+
t.Fatal("DecodeAll:", err)
263+
}
264+
w := new(bytes.Buffer)
265+
err = EncodeAll(w, img)
266+
if err != nil {
267+
t.Fatal("EncodeAll:", err)
268+
}
269+
img1, err := DecodeAll(w)
270+
if err != nil {
271+
t.Fatal("DecodeAll:", err)
272+
}
273+
if img.LoopCount != img1.LoopCount {
274+
t.Errorf("loop count mismatch: %d vs %d", img.LoopCount, img1.LoopCount)
275+
}
276+
}

0 commit comments

Comments
 (0)