From d785af1adb314316ac1c4b63cc671363671fae2e Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Wed, 27 Sep 2023 13:53:43 +0000 Subject: [PATCH] internal/zstd: allow stream consisting of skippable frames For #62513 Change-Id: I2557aed5ae106ea4684bb599cce740e9da9df780 GitHub-Last-Rev: 2b7ddc6c09a7e77874ed9aefc47fbc445d2579ec GitHub-Pull-Request: golang/go#63251 Reviewed-on: https://go-review.googlesource.com/c/go/+/531295 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Bryan Mills LUCI-TryBot-Result: Go LUCI --- src/internal/zstd/zstd.go | 3 ++- src/internal/zstd/zstd_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/internal/zstd/zstd.go b/src/internal/zstd/zstd.go index 1a7a0a381b..6b1aac0c5f 100644 --- a/src/internal/zstd/zstd.go +++ b/src/internal/zstd/zstd.go @@ -169,7 +169,7 @@ retry: // Read magic number. RFC 3.1.1. 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 { err = io.ErrUnexpectedEOF } @@ -183,6 +183,7 @@ retry: if err := r.skipFrame(); err != nil { return err } + r.readOneFrame = true goto retry } diff --git a/src/internal/zstd/zstd_test.go b/src/internal/zstd/zstd_test.go index e5c964c307..8c7f9403c1 100644 --- a/src/internal/zstd/zstd_test.go +++ b/src/internal/zstd/zstd_test.go @@ -97,6 +97,17 @@ var tests = []struct { "", "\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) {