Skip to content

Commit b8d2d6b

Browse files
committed
image/gif: accept LZW encodings that do not have an explicit end marker.
The spec says this is invalid, but it matches giflib's behavior. Fixes #9856 (together with https://go-review.googlesource.com/11661). Change-Id: I05701f62a9e5e724a2d85c6b87ae4111e537146b Reviewed-on: https://go-review.googlesource.com/11663 Reviewed-by: Rob Pike <[email protected]>
1 parent fea18f5 commit b8d2d6b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/image/gif/reader.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,18 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error {
202202
}
203203
return errNotEnough
204204
}
205-
// Both lzwr and br should be exhausted. Reading from them
206-
// should yield (0, io.EOF).
207-
if n, err := lzwr.Read(d.tmp[:1]); n != 0 || err != io.EOF {
205+
// Both lzwr and br should be exhausted. Reading from them should
206+
// yield (0, io.EOF).
207+
//
208+
// The spec (Appendix F - Compression), says that "An End of
209+
// Information code... must be the last code output by the encoder
210+
// for an image". In practice, though, giflib (a widely used C
211+
// library) does not enforce this, so we also accept lzwr returning
212+
// io.ErrUnexpectedEOF (meaning that the encoded stream hit io.EOF
213+
// before the LZW decoder saw an explict end code), provided that
214+
// the io.ReadFull call above successfully read len(m.Pix) bytes.
215+
// See http://golang.org/issue/9856 for an example GIF.
216+
if n, err := lzwr.Read(d.tmp[:1]); n != 0 || (err != io.EOF && err != io.ErrUnexpectedEOF) {
208217
if err != nil {
209218
return err
210219
}

0 commit comments

Comments
 (0)