From ccec93481483f03ad51005b48d6962a52f0ab359 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 18 Jun 2015 14:45:38 +1000 Subject: [PATCH] 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 --- src/compress/lzw/writer.go | 13 ++++++++++--- src/compress/lzw/writer_test.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) 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)) -- 2.50.0