File tree 1 file changed +12
-3
lines changed 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -202,9 +202,18 @@ func (d *decoder) decode(r io.Reader, configOnly bool) error {
202
202
}
203
203
return errNotEnough
204
204
}
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 ) {
208
217
if err != nil {
209
218
return err
210
219
}
You can’t perform that action at this time.
0 commit comments