Commit f467803d authored by Nigel Tao's avatar Nigel Tao

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
parent a4dee3a7
...@@ -165,16 +165,19 @@ func decode1(pw *io.PipeWriter, r io.ByteReader, read func(*decoder) (uint16, os ...@@ -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 { if _, err := w.Write(buf[i:]); err != nil {
return err return err
} }
if last != invalidCode {
// Save what the hi code expands to. // Save what the hi code expands to.
suffix[hi] = uint8(c) suffix[hi] = uint8(c)
prefix[hi] = last prefix[hi] = last
}
default: default:
return os.NewError("lzw: invalid code") return os.NewError("lzw: invalid code")
} }
last, hi = code, hi+1 last, hi = code, hi+1
if hi == overflow { if hi >= overflow {
if d.width == maxWidth { if d.width == maxWidth {
return os.NewError("lzw: missing clear code") last = invalidCode
continue
} }
d.width++ d.width++
overflow <<= 1 overflow <<= 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment