json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.33k stars 1.02k forks source link

Bug: panic when jsoniter.Marshal map[string]string #681

Open s6816112 opened 1 year ago

s6816112 commented 1 year ago

go version go1.20.4 darwin/arm64 gomod: github.com/json-iterator/go v1.1.9 ` func main() { fn := func(args ...interface{}) (interface{}, error) { if len(args) == 0 { return nil, nil } var data map[string]interface{} a := args[0] bt, _ := jsoniter.Marshal(a) jsoniter.Unmarshal(bt, &data) res := make([]string, 0, len(data)) for k := range data { res = append(res, k) } return res, nil } fn(map[string]string{ "a": "1", "b": "2", })

} ` panicStack: unexpected fault address 0x36080808e47f7649 fatal error: fault [signal SIGSEGV: segmentation violation code=0x2 addr=0x36080808e47f7649 pc=0x100363c20]

goroutine 1 [running]: runtime.throw({0x1004a4879?, 0x1005506c0?}) /opt/homebrew/opt/go/libexec/src/runtime/panic.go:1047 +0x40 fp=0x14000111af0 sp=0x14000111ac0 pc=0x1003360f0 runtime.sigpanic() /opt/homebrew/opt/go/libexec/src/runtime/signal_unix.go:851 +0x1a8 fp=0x14000111b30 sp=0x14000111af0 pc=0x10034c948 aeshashbody() /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:791 +0x2d0 fp=0x14000111b40 sp=0x14000111b40 pc=0x100363c20 runtime.mapiternext(0x1400007ea40) /opt/homebrew/opt/go/libexec/src/runtime/map.go:936 +0x2d0 fp=0x14000111bb0 sp=0x14000111b40 pc=0x100312350 runtime.mapiterinit(0x14000075e10?, 0x100533b20?, 0x14000111c28?) /opt/homebrew/opt/go/libexec/src/runtime/map.go:863 +0x2e4 fp=0x14000111be0 sp=0x14000111bb0 pc=0x100312044 reflect.mapiterinit(0x100528c00?, 0x14000146540?, 0x14000111c98?) /opt/homebrew/opt/go/libexec/src/runtime/map.go:1375 +0x1c fp=0x14000111c10 sp=0x14000111be0 pc=0x100360d0c github.com/modern-go/reflect2.(UnsafeMapType).UnsafeIterate(...) /Users/gg/go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/unsafe_map.go:112 github.com/json-iterator/go.(mapEncoder).Encode(0x14000146510, 0x1400000e4c8, 0x14000024240) /Users/gg/go/pkg/mod/github.com/json-iterator/go@v1.1.9/reflect_map.go:257 +0x244 fp=0x14000111cd0 sp=0x14000111c10 pc=0x100424bd4 github.com/json-iterator/go.(onePtrEncoder).Encode(0x14000011630, 0x14000146390, 0x1400007ea40?) /Users/gg/go/pkg/mod/github.com/json-iterator/go@v1.1.9/reflect.go:219 +0x88 fp=0x14000111d10 sp=0x14000111cd0 pc=0x10041e0a8 github.com/json-iterator/go.(Stream).WriteVal(0x14000024240, {0x100529bc0, 0x14000146390}) /Users/gg/go/pkg/mod/github.com/json-iterator/go@v1.1.9/reflect.go:98 +0x178 fp=0x14000111d90 sp=0x14000111d10 pc=0x10041d4b8 github.com/json-iterator/go.(*frozenConfig).Marshal(0x14000114140, {0x100529bc0, 0x14000146390}) /Users/gg/go/pkg/mod/github.com/json-iterator/go@v1.1.9/config.go:299 +0x88 fp=0x14000111e30 sp=0x14000111d90 pc=0x100416008 github.com/json-iterator/go.Marshal(...) /Users/gg/go/pkg/mod/github.com/json-iterator/go@v1.1.9/adapter.go:34 main.main.func1({0x14000111f58, 0x14000146390?, 0x1004fc7e0?}) /Users/gg/go/src/test/test/main.go:28 +0x70 fp=0x14000111f20 sp=0x14000111e30 pc=0x1004a3ca0 main.main() /Users/gg/go/src/test/test/main.go:36 +0xfc fp=0x14000111f70 sp=0x14000111f20 pc=0x1004a3c0c

logo306142054 commented 1 year ago

Update to v1.1.12 will resolve this problem

s6816112 commented 1 year ago

Update to v1.1.12 will resolve this problem

thanks