Skip to content

Commit

Permalink
internal/zstd: allow stream consisting of skippable frames
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderYastrebov committed Sep 27, 2023
1 parent 11084a9 commit 2b7ddc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/internal/zstd/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -183,6 +183,7 @@ retry:
if err := r.skipFrame(); err != nil {
return err
}
r.readOneFrame = true
goto retry
}

Expand Down
11 changes: 11 additions & 0 deletions src/internal/zstd/zstd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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) {
Expand Down

0 comments on commit 2b7ddc6

Please sign in to comment.