]> Cypherpunks.ru repositories - gostls13.git/commitdiff
internal/zstd: allow empty compressed blocks
authorAlexander Yastrebov <yastrebov.alex@gmail.com>
Wed, 27 Sep 2023 02:01:46 +0000 (02:01 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 27 Sep 2023 13:04:05 +0000 (13:04 +0000)
For #62513

Change-Id: I295e72f71165665b8ea999e68a5586fa785b546d
GitHub-Last-Rev: 902e952d88dba505f87393fd3c97c433ae291709
GitHub-Pull-Request: golang/go#63252
Reviewed-on: https://go-review.googlesource.com/c/go/+/531217
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/internal/zstd/block.go
src/internal/zstd/zstd_test.go

index cf4c954c7d5dc833a94a3b9bb87c6fa36f255ebb..8732661fa1d9a310000292ccec73129120796aca 100644 (file)
@@ -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
        }
 
@@ -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")
index 22af814acfce57d8344436394c128a13dc748431..c2914bb1f4f29408f7da17042c7992c552ad3159 100644 (file)
@@ -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) {