Skip to content

Extra bytes at the end of encoded buffer (zstd) #277

@Feresey

Description

@Feresey

I have found that current implementation of zstd (v1.10.10) adds three extra bytes to the end of encoded byte stream (01 00 00). These bytes makes unable to uncompress archive with standard GNU zstd utility.

Example code:

package main

import (
	"bytes"
	"fmt"
	"strings"

	"github.com/klauspost/compress/zstd"
)

var src = `0`

func main() {
	buffer := bytes.NewBuffer(nil)
	encoder, err := zstd.NewWriter(buffer)
	if err != nil {
		panic(err)
	}
	if _, err := encoder.ReadFrom(strings.NewReader(src)); err != nil {
		panic(err)
	}
	if err := encoder.Close(); err != nil {
		panic(err)
	}
	fmt.Printf("% x\n", buffer.Bytes())
}

Prints: 28 b5 2f fd 04 00 09 00 00 30 ec af 44 12 01 00 00

At the same time with GNU zstd:

$ echo -n 0 | zstd | hexdump -C
00000000  28 b5 2f fd 04 58 09 00  00 30 ec af 44 12        |(./..X...0..D.|
0000000e

Note last 3 extra bytes.

Also, version 1.9.0 works like the GNU zstd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions