From: Nigel Tao Date: Sun, 8 May 2011 01:57:32 +0000 (-0700) Subject: compress/lzw: silently drop implied codes that are too large, X-Git-Tag: weekly.2011-05-22~131 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f467803dcd84e38df5ad2ee90613b1a088090071;p=gostls13.git compress/lzw: silently drop implied codes that are too large, instead of returning an error. For example, http://www.w3.org/Graphics/GIF/spec-gif89a.txt explicitly says that GIF encoders can use a full table as is, without needing to send a clear code. R=r, dsymonds, nigeltao_gnome, r2 CC=golang-dev https://golang.org/cl/4518041 --- diff --git a/src/pkg/compress/lzw/reader.go b/src/pkg/compress/lzw/reader.go index d418bc8561..a1cd2abc04 100644 --- a/src/pkg/compress/lzw/reader.go +++ b/src/pkg/compress/lzw/reader.go @@ -165,16 +165,19 @@ func decode1(pw *io.PipeWriter, r io.ByteReader, read func(*decoder) (uint16, os if _, err := w.Write(buf[i:]); err != nil { return err } - // Save what the hi code expands to. - suffix[hi] = uint8(c) - prefix[hi] = last + if last != invalidCode { + // Save what the hi code expands to. + suffix[hi] = uint8(c) + prefix[hi] = last + } default: return os.NewError("lzw: invalid code") } last, hi = code, hi+1 - if hi == overflow { + if hi >= overflow { if d.width == maxWidth { - return os.NewError("lzw: missing clear code") + last = invalidCode + continue } d.width++ overflow <<= 1