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

Can not work with archive/tar #98

Closed
keeword opened this issue Mar 6, 2021 · 1 comment
Closed

Can not work with archive/tar #98

keeword opened this issue Mar 6, 2021 · 1 comment

Comments

@keeword
Copy link

keeword commented Mar 6, 2021

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.15.8 linux/amd64

What operating system and processor architecture are you using (go env)?

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOROOT="/usr/lib/go-1.15"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.15/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build135663132=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to work with package "archive/tar".

package main

import (
	"archive/tar"
	"io"
	"os"

	"github.com/DataDog/zstd"
)

func main() {
	out, err := os.Create("out.tar.zstd")
	if err != nil {
		panic(err)
	}
	defer out.Close()

	in := "infile.txt"
	fi, err := os.Stat(in)
	if err != nil {
		panic(err)
	}

	zw := zstd.NewWriter(out)
	defer zw.Close()

	tw := tar.NewWriter(zw)
	defer tw.Close()

	hdr, err := tar.FileInfoHeader(fi, fi.Name())
	if err != nil {
		panic(err)
	}

	if err := tw.WriteHeader(hdr); err != nil {
		panic(err)
	}

	file, err := os.OpenFile(in, os.O_RDONLY, 0)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	if _, err := io.Copy(tw, file); err != nil {
		panic(err)
	}
}

What did you expect to see?

Generate a tar and compressed file.

What did you see instead?

panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/DataDog/zstd.(*Writer).Write.func1(0xc000020080, 0xc00010cb80, 0xc00010cb80, 0x200, 0x200)
        /root/go/pkg/mod/github.com/!data!dog/zstd@v1.4.8/zstd_stream.go:181 +0xe5
github.com/DataDog/zstd.(*Writer).Write(0xc000020080, 0xc00010cb80, 0x200, 0x200, 0x1648, 0x0, 0x0)
        /root/go/pkg/mod/github.com/!data!dog/zstd@v1.4.8/zstd_stream.go:181 +0xf5
archive/tar.(*Writer).writeRawHeader(0xc00010ca80, 0xc00010cb80, 0x50aba0, 0x30, 0x0, 0x0)
        /usr/lib/go-1.15/src/archive/tar/writer.go:392 +0x7d
archive/tar.(*Writer).writeUSTARHeader(0xc00010ca80, 0xc00010caa8, 0xa, 0x0)
        /usr/lib/go-1.15/src/archive/tar/writer.go:125 +0x1be
archive/tar.(*Writer).WriteHeader(0xc00010ca80, 0xc00011a000, 0x59e34c, 0xa)
        /usr/lib/go-1.15/src/archive/tar/writer.go:97 +0x2e5
main.main()
        /root/test/main.go:34 +0x287
@Viq111
Copy link
Collaborator

Viq111 commented Mar 8, 2021

Hi @keeword , thanks for the report.
We are tracking this in #97 and will fix asap.

Once it's merged (very likely this week), it should fix this issue

@Viq111 Viq111 closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants