1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:55:01 -07:00

internal/zstd: reset reader buffer

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

For #62513

Change-Id: Icb65e76b5c5c0af32b36ec3a5999dca86407cbc8
GitHub-Last-Rev: 99c0a6fa72
GitHub-Pull-Request: golang/go#63288
Reviewed-on: https://go-review.googlesource.com/c/go/+/531735
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Alexander Yastrebov 2023-09-28 22:26:57 +00:00 committed by Gopher Robot
parent 8c3924c656
commit 20944cf066
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