Open ryan-ju opened 3 months ago
Version
v0.10.3
Example code
package main import ( "fmt" stdjson "encoding/json" "github.com/goccy/go-json" ) type A struct { B *B `json:"b"` } type B struct { Foo *string `json:"foo"` Bar *string `json:"bar"` } func main() { str := "hello" v := A{ B: &B{ Foo: &str, }, } bs, _ := stdjson.Marshal(v) fmt.Println(string(bs)) // Prints {"b":{"foo":"hello","bar":"hello"}} bs, _ = json.Marshal(v) // Panics fmt.Println(string(bs)) }
Console output
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0xd pc=0xec25303] goroutine 1 [running]: github.com/goccy/go-json/internal/encoder/vm.ptrToString(...) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/internal/encoder/vm/util.go:89 github.com/goccy/go-json/internal/encoder/vm.Run(0xc000108d00, {0xc000018400?, 0x0?, 0x0?}, 0xc00002bd88?) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/internal/encoder/vm/vm.go:4580 +0x1efe3 github.com/goccy/go-json.encodeRunCode(0xc000108d00?, {0xc000018400?, 0xc00002bdd0?, 0xc0000300c0?}, 0xc000018800?) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/encode.go:310 +0x56 github.com/goccy/go-json.encode(0xc000108d00, {0xec82040, 0xc000014090}) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/encode.go:235 +0x205 github.com/goccy/go-json.marshal({0xec82040, 0xc000014090}, {0x0, 0x0, 0x0?}) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/encode.go:150 +0xb9 github.com/goccy/go-json.MarshalWithOption(...) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/json.go:185 github.com/goccy/go-json.Marshal({0xec82040?, 0xc000014090?}) /Users/ran/.gvm/pkgsets/go1.22.1/global/pkg/mod/github.com/goccy/go-json@v0.10.3/json.go:170 +0x25 main.main() /Users/ran/Projects/xxx/tmp/main.go:109 +0xd7
go env
GO111MODULE='on' GOARCH='amd64' GOBIN='' GOEXE='' GOEXPERIMENT='' GOFLAGS='-mod=mod' GOHOSTARCH='amd64' GOHOSTOS='darwin' GOINSECURE='' GOOS='darwin' GOPROXY='https://goproxy.io,direct' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOVCS='' GOVERSION='go1.22.1' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/sp/kyrr5gqs3z719c7lv933_cpr0000gn/T/go-build3263209783=/tmp/go-build -gno-record-gcc-switches -fno-common'
This is a very serious bug, given how easy it is to reproduce
Version
Example code
Console output
go env