]> Cypherpunks repositories - gostls13.git/commitdiff
internal/zstd: fix window resizing
authorAlexander Yastrebov <yastrebov.alex@gmail.com>
Sat, 9 Sep 2023 00:20:40 +0000 (00:20 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 13 Sep 2023 18:34:35 +0000 (18:34 +0000)
Incorrect window resizing led to checksum error and invalid result.
To demonstrate the problem bigData must be a bit bigger, 3x is enough.

This change fixes window resizing, increases bigData size and decouples
TestLargeXXHash from bigData because it uses hardcoded hash value.

Change-Id: I50f74315b083f42e1ccd7ab2093e084f44631bb6
GitHub-Last-Rev: dbc90ba7a5f24db198cc3eab1c38aad665e41d06
GitHub-Pull-Request: golang/go#62543
Reviewed-on: https://go-review.googlesource.com/c/go/+/527115
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/internal/zstd/xxhash_test.go
src/internal/zstd/zstd.go
src/internal/zstd/zstd_test.go

index 646cee888a5c7c2439a015804560b81ce1e1f40c..032739fbc014dd9d7d0e356ff45319c5e559b755 100644 (file)
@@ -42,7 +42,11 @@ func TestLargeXXHash(t *testing.T) {
                t.Skip("skipping expensive test in short mode")
        }
 
-       data := bigData(t)
+       data, err := os.ReadFile("../../testdata/Isaac.Newton-Opticks.txt")
+       if err != nil {
+               t.Fatal(err)
+       }
+
        var xh xxhash64
        xh.reset()
        i := 0
index a8607893cd4a2f8bad25875b726165c51764bdc6..25a731c1649e37189e5bb629c498b8b2312fc816 100644 (file)
@@ -466,6 +466,7 @@ func (r *Reader) saveWindow(buf []byte) {
        if keep < len(r.window) {
                remove := len(r.window) - keep
                copy(r.window[:], r.window[remove:])
+               r.window = r.window[:keep]
        }
 
        r.window = append(r.window, buf...)
index bc75e0fb039e4724ad6e1591a489708e218c9f73..33f3def878eb52fa4e0e6410c59e3cfbfb2c7158 100644 (file)
@@ -115,10 +115,13 @@ var (
        bigDataErr   error
 )
 
-// bigData returns the contents of our large test file.
+// bigData returns the contents of our large test file repeated multiple times.
 func bigData(t testing.TB) []byte {
        bigDataOnce.Do(func() {
                bigDataBytes, bigDataErr = os.ReadFile("../../testdata/Isaac.Newton-Opticks.txt")
+               if bigDataErr == nil {
+                       bigDataBytes = bytes.Repeat(bigDataBytes, 3)
+               }
        })
        if bigDataErr != nil {
                t.Fatal(bigDataErr)