Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
image/gif: re-enable some invalid-palette tests.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nigeltao committed Jun 19, 2015
1 parent a3c0730 commit 75ce330
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/image/gif/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 75ce330

Please sign in to comment.