]> Cypherpunks repositories - gostls13.git/commitdiff
compress/flate: fix out of bounds error
authorIvan Krasin <krasin@golang.org>
Mon, 12 Dec 2011 23:25:32 +0000 (18:25 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 12 Dec 2011 23:25:32 +0000 (18:25 -0500)
Fixes #2508.

R=rsc, krasin
CC=golang-dev
https://golang.org/cl/5449115

src/pkg/compress/flate/deflate.go
src/pkg/compress/flate/deflate_test.go

index 1f659bab71369bbd3f9cdd95587ef386aa568f26..4f744457dd7e0fc0ad4de36137eaedef2f4ba437 100644 (file)
@@ -319,7 +319,9 @@ Loop:
                                // For matches this long, we don't bother inserting each individual
                                // item into the table.
                                d.index += d.length
-                               d.hash = (int(d.window[d.index])<<hashShift + int(d.window[d.index+1]))
+                               if d.index < d.maxInsertIndex {
+                                       d.hash = (int(d.window[d.index])<<hashShift + int(d.window[d.index+1]))
+                               }
                        }
                        if d.ti == maxFlateBlockTokens {
                                // The block includes the current character
index b4876b0f8b3d25da89469df8677bd6e90e39dcd7..bae5c82305ae0c25e78d74410ec6332a04341190 100644 (file)
@@ -318,3 +318,15 @@ func TestWriterDict(t *testing.T) {
                t.Fatalf("writer wrote %q want %q", b1.Bytes(), b.Bytes())
        }
 }
+
+// See http://code.google.com/p/go/issues/detail?id=2508
+func TestRegression2508(t *testing.T) {
+       w := NewWriter(ioutil.Discard, 1)
+       buf := make([]byte, 1024)
+       for i := 0; i < 131072; i++ {
+               if _, err := w.Write(buf); err != nil {
+                       t.Fatalf("writer failed: %v", err)
+               }
+       }
+       w.Close()
+}