]> Cypherpunks repositories - gostls13.git/commitdiff
compress/lzw: silently drop implied codes that are too large,
authorNigel Tao <nigeltao@golang.org>
Sun, 8 May 2011 01:57:32 +0000 (18:57 -0700)
committerNigel Tao <nigeltao@golang.org>
Sun, 8 May 2011 01:57:32 +0000 (18:57 -0700)
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

src/pkg/compress/lzw/reader.go

index d418bc8561b3702f7523aa8b5c54929db98f243c..a1cd2abc0439e0fea9fb1979eadf73dfc362e54c 100644 (file)
@@ -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