}
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
}