Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zstd.go: Set ZSTD_LEGACY_SUPPORT=4 to decompress legacy payloads #105

Merged
merged 3 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ jobs:
- run: 'unzip mr.zip'
- run: 'go build -tags external_libzstd'
- run: 'PAYLOAD=`pwd`/mr GODEBUG=efence=1 go test -tags external_libzstd -v'
"golang-zstd-legacy-support":
docker:
- image: circleci/golang:latest
steps:
- checkout
- run: 'wget https://github.com/DataDog/zstd/files/2246767/mr.zip'
- run: 'unzip mr.zip'
- run: 'CGO_CFLAGS="-DZSTD_LEGACY_SUPPORT=1" go build'
- run: 'PAYLOAD=`pwd`/mr CGO_CFLAGS="-DZSTD_LEGACY_SUPPORT=1" go test -v'
"golang-i386":
docker:
- image: 32bit/ubuntu:16.04
Expand All @@ -118,4 +109,3 @@ workflows:
- "golang-efence"
- "golang-efence-external-libzstd"
- "golang-i386"
- "golang-zstd-legacy-support"
5 changes: 5 additions & 0 deletions zstd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package zstd

/*
// support decoding of "legacy" zstd payloads from versions [0.4, 0.8], matching the
// default configuration of the zstd command line tool:
// https://github.com/facebook/zstd/blob/dev/programs/README.md
#cgo CFLAGS: -DZSTD_LEGACY_SUPPORT=4

#include "zstd.h"
*/
import "C"
Expand Down
25 changes: 25 additions & 0 deletions zstd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"testing"
)

Expand Down Expand Up @@ -259,6 +261,29 @@ func TestRealPayload(t *testing.T) {
}
}

func TestLegacy(t *testing.T) {
// payloads compressed with zstd v0.5
// needs ZSTD_LEGACY_SUPPORT=5 or less
testCases := []struct {
input string
expected string
}{
{"%\xb5/\xfd\x00@\x00\x1bcompressed with legacy zstd\xc0\x00\x00", "compressed with legacy zstd"},
{"%\xb5/\xfd\x00\x00\x00A\x11\x007\x14\xb0\xb5\x01@\x1aR\xb6iI7[FH\x022u\xe0O-\x18\xe3G\x9e2\xab\xd9\xea\xca7؊\xee\x884\xbf\xe7\xdc\xe4@\xe1-\x9e\xac\xf0\xf2\x86\x0f\xf1r\xbb7\b\x81Z\x01\x00\x01\x00\xdf`\xfe\xc0\x00\x00", "compressed with legacy zstd"},
}
for i, testCase := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
out, err := Decompress(nil, []byte(testCase.input))
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(out), testCase.expected) {
t.Errorf("expected to find %#v; output=%#v", testCase.expected, string(out))
}
})
}
}

func BenchmarkCompression(b *testing.B) {
if raw == nil {
b.Fatal(ErrNoPayloadEnv)
Expand Down