Commit b58ecb11 authored by Nigel Tao's avatar Nigel Tao

Fix inflate.go's decompressing of a fixed Huffman block that has

length-distance pairs.

The new test data was generated by "gzip shesells.txt", which is
presumably what you (rsc) did before, for the other test cases in
gunzip_test.go.

R=rsc
APPROVED=rsc
DELTA=21  (17 added, 2 deleted, 2 changed)
OCL=33582
CL=33616
parent f0ccd407
...@@ -460,7 +460,7 @@ func (f *inflater) decodeBlock(hl, hd *huffmanDecoder) os.Error { ...@@ -460,7 +460,7 @@ func (f *inflater) decodeBlock(hl, hd *huffmanDecoder) os.Error {
return err; return err;
} }
} }
dist = int(f.b & 0x1F); dist = int(reverseByte[(f.b & 0x1F) << 3]);
f.b >>= 5; f.b >>= 5;
f.nb -= 5; f.nb -= 5;
} else { } else {
...@@ -628,7 +628,6 @@ func makeReader(r io.Reader) Reader { ...@@ -628,7 +628,6 @@ func makeReader(r io.Reader) Reader {
// Inflate reads DEFLATE-compressed data from r and writes // Inflate reads DEFLATE-compressed data from r and writes
// the uncompressed data to w. // the uncompressed data to w.
func (f *inflater) inflater(r io.Reader, w io.Writer) os.Error { func (f *inflater) inflater(r io.Reader, w io.Writer) os.Error {
var ok bool; // TODO(rsc): why not := on next line?
f.r = makeReader(r); f.r = makeReader(r);
f.w = w; f.w = w;
f.woffset = 0; f.woffset = 0;
...@@ -643,7 +642,7 @@ func (f *inflater) inflater(r io.Reader, w io.Writer) os.Error { ...@@ -643,7 +642,7 @@ func (f *inflater) inflater(r io.Reader, w io.Writer) os.Error {
// NewInflater returns a new ReadCloser that can be used // NewInflater returns a new ReadCloser that can be used
// to read the uncompressed version of r. It is the caller's // to read the uncompressed version of r. It is the caller's
// responsibility to call Close on the ReadClosed when // responsibility to call Close on the ReadCloser when
// finished reading. // finished reading.
func NewInflater(r io.Reader) io.ReadCloser { func NewInflater(r io.Reader) io.ReadCloser {
var f inflater; var f inflater;
......
...@@ -8,8 +8,8 @@ import ( ...@@ -8,8 +8,8 @@ import (
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "io";
"testing";
"os"; "os";
"testing";
) )
type gzipTest struct { type gzipTest struct {
...@@ -68,6 +68,22 @@ var gzipTests = []gzipTest { ...@@ -68,6 +68,22 @@ var gzipTests = []gzipTest {
}, },
nil nil
}, },
gzipTest { // has a fixed huffman block with some length-distance pairs
"shesells.txt",
"shesells.txt",
"she sells seashells by the seashore\n",
[]byte {
0x1f, 0x8b, 0x08, 0x08, 0x72, 0x66, 0x8b, 0x4a,
0x00, 0x03, 0x73, 0x68, 0x65, 0x73, 0x65, 0x6c,
0x6c, 0x73, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x2b,
0xce, 0x48, 0x55, 0x28, 0x4e, 0xcd, 0xc9, 0x29,
0x06, 0x92, 0x89, 0xc5, 0x19, 0x60, 0x56, 0x52,
0xa5, 0x42, 0x09, 0x58, 0x18, 0x28, 0x90, 0x5f,
0x94, 0xca, 0x05, 0x00, 0x76, 0xb0, 0x3b, 0xeb,
0x24, 0x00, 0x00, 0x00,
},
nil
},
gzipTest { // has dynamic huffman blocks gzipTest { // has dynamic huffman blocks
"gettysburg", "gettysburg",
"gettysburg", "gettysburg",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment