Skip to content

Commit

Permalink
internal/zstd: allow empty compressed blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderYastrebov committed Sep 27, 2023
1 parent 5e9afab commit 902e952
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/internal/zstd/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func (r *Reader) compressedBlock(blockSize int) error {
if off < len(data) {
return r.makeError(off, "extraneous data after no sequences")
}
if len(litbuf) == 0 {
return r.makeError(off, "no sequences and no literals")
}

r.buffer = append(r.buffer, litbuf...)

return nil
}

Expand Down Expand Up @@ -374,9 +373,7 @@ func (r *Reader) execSeqs(data block, off int, litbuf []byte, seqCount int) erro
}
}

if len(litbuf) > 0 {
r.buffer = append(r.buffer, litbuf...)
}
r.buffer = append(r.buffer, litbuf...)

if rbr.cnt != 0 {
return r.makeError(off, "extraneous data after sequences")
Expand Down
5 changes: 5 additions & 0 deletions src/internal/zstd/zstd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ var tests = []struct {
"0\x00\x00\x00\x00\x000\x00\x00\x00\x00\x001\x00\x00\x00\x00\x000000",
"(\xb5/\xfd\x04X\x8d\x00\x00P0\x000\x001\x000000\x03T\x02\x00\x01\x01m\xf9\xb7G",
},
{
"empty block",
"",
"\x28\xb5\x2f\xfd\x00\x00\x15\x00\x00\x00\x00",
},
}

func TestSamples(t *testing.T) {
Expand Down

0 comments on commit 902e952

Please sign in to comment.