From 75ce33068d8c2c45f40e599ae2d4c80cb8b919d7 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 19 Jun 2015 15:39:11 +1000 Subject: [PATCH] image/gif: re-enable some invalid-palette tests. These tests were broken by https://go-review.googlesource.com/#/c/11227/ which fixed the LZW encoder to reject invalid input. For TestNoPalette, the LZW encoder with a litWidth of 2 now rejects an input byte of 128, so we change 128 to 3, as 3 <= (1<<2 - 1). For TestPixelOutsidePaletteRange, the LZW encoder similarly rejects an input byte of 255. Prior to golang.org/cl/11227, the encoder (again with a litWidth of 2) accepted the 255 input byte, but masked it with (1<<2 - 1), so that the 255 test case was effectively the same as the 3 test case. After that LZW CL, the 255 input byte is simply invalid, so we remove it as a test case. The test still tests pixels outside of the palette range, since 3 >= the length of the global palette, which is 2. Change-Id: I50be9623ace016740e34801549c15f83671103eb Reviewed-on: https://go-review.googlesource.com/11273 Reviewed-by: David Symonds --- src/image/gif/reader_test.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/image/gif/reader_test.go b/src/image/gif/reader_test.go index fd0000886c..0d0017e5b8 100644 --- a/src/image/gif/reader_test.go +++ b/src/image/gif/reader_test.go @@ -189,12 +189,6 @@ func TestBounds(t *testing.T) { } func TestNoPalette(t *testing.T) { - // https://go-review.googlesource.com/#/c/11227/ - // changed the lzw encoder to reject input bytes that are too large, - // so that this test code no longer generates the right invalid GIF. - // TODO(nigeltao): re-enable this test somehow. - return - b := &bytes.Buffer{} // Manufacture a GIF with no palette, so any pixel at all @@ -206,11 +200,15 @@ func TestNoPalette(t *testing.T) { b.WriteString("\x2c\x00\x00\x00\x00\x02\x00\x01\x00\x00\x02") // Encode the pixels: neither is in range, because there is no palette. - pix := []byte{0, 128} + pix := []byte{0, 3} enc := &bytes.Buffer{} w := lzw.NewWriter(enc, lzw.LSB, 2) - w.Write(pix) - w.Close() + if _, err := w.Write(pix); err != nil { + t.Fatalf("Write: %v", err) + } + if err := w.Close(); err != nil { + t.Fatalf("Close: %v", err) + } b.WriteByte(byte(len(enc.Bytes()))) b.Write(enc.Bytes()) b.WriteByte(0x00) // An empty block signifies the end of the image data. @@ -221,13 +219,7 @@ func TestNoPalette(t *testing.T) { } func TestPixelOutsidePaletteRange(t *testing.T) { - // https://go-review.googlesource.com/#/c/11227/ - // changed the lzw encoder to reject input bytes that are too large, - // so that this test code no longer generates the right invalid GIF. - // TODO(nigeltao): re-enable this test somehow. - return - - for _, pval := range []byte{0, 1, 2, 3, 255} { + for _, pval := range []byte{0, 1, 2, 3} { b := &bytes.Buffer{} // Manufacture a GIF with a 2 color palette. @@ -241,8 +233,12 @@ func TestPixelOutsidePaletteRange(t *testing.T) { pix := []byte{pval, pval} enc := &bytes.Buffer{} w := lzw.NewWriter(enc, lzw.LSB, 2) - w.Write(pix) - w.Close() + if _, err := w.Write(pix); err != nil { + t.Fatalf("Write: %v", err) + } + if err := w.Close(); err != nil { + t.Fatalf("Close: %v", err) + } b.WriteByte(byte(len(enc.Bytes()))) b.Write(enc.Bytes()) b.WriteByte(0x00) // An empty block signifies the end of the image data.