]> Cypherpunks repositories - gostls13.git/commitdiff
image/gif: re-enable some invalid-palette tests.
authorNigel Tao <nigeltao@golang.org>
Fri, 19 Jun 2015 05:39:11 +0000 (15:39 +1000)
committerNigel Tao <nigeltao@golang.org>
Fri, 19 Jun 2015 06:14:38 +0000 (06:14 +0000)
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 <dsymonds@golang.org>
src/image/gif/reader_test.go

index fd0000886ccbce0d0905f205924c775da532c173..0d0017e5b809a50102113507bb0efedafb0479e6 100644 (file)
@@ -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.