summaryrefslogtreecommitdiff
path: root/libgo/go/compress/flate
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-06-25 16:20:03 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-06-25 16:20:03 +0000
commit4b786d35e0af0c254988199551709abef06b925e (patch)
tree5dfe28c3f573ae57b971ed4d9a1c99a76f0a70c4 /libgo/go/compress/flate
parent2e6c5d723ff7407704f2cbd343383991b498fb5b (diff)
downloadgcc-4b786d35e0af0c254988199551709abef06b925e.tar.gz
libgo: Update to Go 1.0.2 release.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@188943 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/compress/flate')
-rw-r--r--libgo/go/compress/flate/deflate.go20
-rw-r--r--libgo/go/compress/flate/deflate_test.go44
2 files changed, 64 insertions, 0 deletions
diff --git a/libgo/go/compress/flate/deflate.go b/libgo/go/compress/flate/deflate.go
index 20408409c8e..e511b50fd1b 100644
--- a/libgo/go/compress/flate/deflate.go
+++ b/libgo/go/compress/flate/deflate.go
@@ -32,6 +32,7 @@ const (
hashSize = 1 << hashBits
hashMask = (1 << hashBits) - 1
hashShift = (hashBits + minMatchLength - 1) / minMatchLength
+ maxHashOffset = 1 << 24
skipNever = math.MaxInt32
)
@@ -106,6 +107,25 @@ func (d *compressor) fillDeflate(b []byte) int {
d.blockStart = math.MaxInt32
}
d.hashOffset += windowSize
+ if d.hashOffset > maxHashOffset {
+ delta := d.hashOffset - 1
+ d.hashOffset -= delta
+ d.chainHead -= delta
+ for i, v := range d.hashPrev {
+ if v > delta {
+ d.hashPrev[i] -= delta
+ } else {
+ d.hashPrev[i] = 0
+ }
+ }
+ for i, v := range d.hashHead {
+ if v > delta {
+ d.hashHead[i] -= delta
+ } else {
+ d.hashHead[i] = 0
+ }
+ }
+ }
}
n := copy(d.window[d.windowEnd:], b)
d.windowEnd += n
diff --git a/libgo/go/compress/flate/deflate_test.go b/libgo/go/compress/flate/deflate_test.go
index 543c5950586..f1e6db2ace4 100644
--- a/libgo/go/compress/flate/deflate_test.go
+++ b/libgo/go/compress/flate/deflate_test.go
@@ -94,6 +94,50 @@ func TestDeflate(t *testing.T) {
}
}
+// A sparseReader returns a stream consisting of 0s followed by 1<<16 1s.
+// This tests missing hash references in a very large input.
+type sparseReader struct {
+ l int64
+ cur int64
+}
+
+func (r *sparseReader) Read(b []byte) (n int, err error) {
+ if r.cur >= r.l {
+ return 0, io.EOF
+ }
+ n = len(b)
+ cur := r.cur + int64(n)
+ if cur > r.l {
+ n -= int(cur - r.l)
+ cur = r.l
+ }
+ for i := range b[0:n] {
+ if r.cur+int64(i) >= r.l-1<<16 {
+ b[i] = 1
+ } else {
+ b[i] = 0
+ }
+ }
+ r.cur = cur
+ return
+}
+
+func TestVeryLongSparseChunk(t *testing.T) {
+ if testing.Short() {
+ t.Logf("skipping sparse chunk during short test")
+ return
+ }
+ w, err := NewWriter(ioutil.Discard, 1)
+ if err != nil {
+ t.Errorf("NewWriter: %v", err)
+ return
+ }
+ if _, err = io.Copy(w, &sparseReader{l: 23E8}); err != nil {
+ t.Errorf("Compress failed: %v", err)
+ return
+ }
+}
+
type syncBuffer struct {
buf bytes.Buffer
mu sync.RWMutex