aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2015-06-29 16:43:25 +1000
committerNigel Tao <nigeltao@golang.org>2015-06-30 03:47:51 +0000
commitb8d2d6b9c0fcd66fe9579d7525d4ec5ecc2d73a3 (patch)
tree6fd5cc35e18abdde08c628913903b06000c23259
parentfea18f5a341e442783f84703a78924b882aceb5e (diff)
downloadgo-b8d2d6b9c0fcd66fe9579d7525d4ec5ecc2d73a3.tar.gz
go-b8d2d6b9c0fcd66fe9579d7525d4ec5ecc2d73a3.zip
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 <r@golang.org>
-rw-r--r--src/image/gif/reader.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/image/gif/reader.go b/src/image/gif/reader.go
index cf5af210a6..a1da69780c 100644
--- a/src/image/gif/reader.go
+++ b/src/image/gif/reader.go
@@ -202,9 +202,18 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error {
}
return errNotEnough
}
- // Both lzwr and br should be exhausted. Reading from them
- // should yield (0, io.EOF).
- if n, err := lzwr.Read(d.tmp[:1]); n != 0 || err != io.EOF {
+ // Both lzwr and br should be exhausted. Reading from them should
+ // yield (0, io.EOF).
+ //
+ // The spec (Appendix F - Compression), says that "An End of
+ // Information code... must be the last code output by the encoder
+ // for an image". In practice, though, giflib (a widely used C
+ // library) does not enforce this, so we also accept lzwr returning
+ // io.ErrUnexpectedEOF (meaning that the encoded stream hit io.EOF
+ // before the LZW decoder saw an explict end code), provided that
+ // the io.ReadFull call above successfully read len(m.Pix) bytes.
+ // See http://golang.org/issue/9856 for an example GIF.
+ if n, err := lzwr.Read(d.tmp[:1]); n != 0 || (err != io.EOF && err != io.ErrUnexpectedEOF) {
if err != nil {
return err
}