From: Nigel Tao Date: Thu, 18 Jun 2015 04:45:38 +0000 (+1000) Subject: compress/lzw: reject writing bytes that don't fit into litWidth. X-Git-Tag: go1.5beta1~186 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ccec93481483f03ad51005b48d6962a52f0ab359;p=gostls13.git compress/lzw: reject writing bytes that don't fit into litWidth. Fixes #11142. Change-Id: Id772c4364c47776d6afe86b0939b9c6281e85edc Reviewed-on: https://go-review.googlesource.com/11227 Reviewed-by: Russ Cox --- diff --git a/src/compress/lzw/writer.go b/src/compress/lzw/writer.go index e9314fc474..7367c29651 100644 --- a/src/compress/lzw/writer.go +++ b/src/compress/lzw/writer.go @@ -138,16 +138,23 @@ func (e *encoder) Write(p []byte) (n int, err error) { if len(p) == 0 { return 0, nil } + if maxLit := uint8(1< maxLit { + e.err = errors.New("lzw: input byte too large for the litWidth") + return 0, e.err + } + } + } n = len(p) - litMask := uint32(1<= 1<<2: got nil error, want non-nil") + } +} + func benchmarkEncoder(b *testing.B, n int) { b.StopTimer() b.SetBytes(int64(n))