Skip to content

Commit

Permalink
internal/zstd: fix window resizing
Browse files Browse the repository at this point in the history
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: dbc90ba
GitHub-Pull-Request: golang#62543
Reviewed-on: https://go-review.googlesource.com/c/go/+/527115
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
AlexanderYastrebov authored and gopherbot committed Sep 13, 2023
1 parent dc0d126 commit 3e1db32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/internal/zstd/xxhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/internal/zstd/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
5 changes: 4 additions & 1 deletion src/internal/zstd/zstd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3e1db32

Please sign in to comment.