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

internal/zstd: reset reader buffer

Reset r.buffer on Reset to avoid subsequent Read calls observing
previously decoded data.

For #62513
This commit is contained in:
Alexander Yastrebov 2023-09-28 23:45:33 +02:00
parent 5351bcf822
commit 99c0a6fa72
2 changed files with 21 additions and 1 deletions

View File

@ -104,7 +104,7 @@ func (r *Reader) Reset(input io.Reader) {
r.frameSizeUnknown = false
r.remainingFrameSize = 0
r.blockOffset = 0
// buffer
r.buffer = r.buffer[:0]
r.off = 0
// repeatedOffset1
// repeatedOffset2

View File

@ -127,6 +127,26 @@ func TestSamples(t *testing.T) {
}
}
func TestReset(t *testing.T) {
input := strings.NewReader("")
r := NewReader(input)
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
input.Reset(test.compressed)
r.Reset(input)
got, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
gotstr := string(got)
if gotstr != test.uncompressed {
t.Errorf("got %q want %q", gotstr, test.uncompressed)
}
})
}
}
var (
bigDataOnce sync.Once
bigDataBytes []byte