1
0
mirror of https://github.com/golang/go synced 2024-11-05 12:06:15 -07:00

internal/zstd: fix window resizing

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.
This commit is contained in:
Alexander Yastrebov 2023-09-09 01:58:07 +02:00
parent 4651c0c6d9
commit dbc90ba7a5
3 changed files with 10 additions and 2 deletions

View 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

View 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...)

View 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)