1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:04:45 -07:00

internal/zstd: allow stream consisting of skippable frames

For #62513

Change-Id: I2557aed5ae106ea4684bb599cce740e9da9df780
GitHub-Last-Rev: 2b7ddc6c09
GitHub-Pull-Request: golang/go#63251
Reviewed-on: https://go-review.googlesource.com/c/go/+/531295
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Alexander Yastrebov 2023-09-27 13:53:43 +00:00 committed by Gopher Robot
parent 6cf6067d4e
commit d785af1adb
2 changed files with 13 additions and 1 deletions

View File

@ -169,7 +169,7 @@ retry:
// Read magic number. RFC 3.1.1. // Read magic number. RFC 3.1.1.
if _, err := io.ReadFull(r.r, r.scratch[:4]); err != nil { if _, err := io.ReadFull(r.r, r.scratch[:4]); err != nil {
// We require that the stream contain at least one frame. // We require that the stream contains at least one frame.
if err == io.EOF && !r.readOneFrame { if err == io.EOF && !r.readOneFrame {
err = io.ErrUnexpectedEOF err = io.ErrUnexpectedEOF
} }
@ -183,6 +183,7 @@ retry:
if err := r.skipFrame(); err != nil { if err := r.skipFrame(); err != nil {
return err return err
} }
r.readOneFrame = true
goto retry goto retry
} }

View File

@ -97,6 +97,17 @@ var tests = []struct {
"", "",
"\x28\xb5\x2f\xfd\x00\x00\x15\x00\x00\x00\x00", "\x28\xb5\x2f\xfd\x00\x00\x15\x00\x00\x00\x00",
}, },
{
"single skippable frame",
"",
"\x50\x2a\x4d\x18\x00\x00\x00\x00",
},
{
"two skippable frames",
"",
"\x50\x2a\x4d\x18\x00\x00\x00\x00" +
"\x50\x2a\x4d\x18\x00\x00\x00\x00",
},
} }
func TestSamples(t *testing.T) { func TestSamples(t *testing.T) {