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

MarshalToString "map[string]bool" get error: unexpected fault address 0xffffffffffffffff #658

Open
newproplus opened this issue Feb 18, 2023 · 4 comments

Comments

@newproplus
Copy link

package main

import (
	"fmt"

	jsoniter "github.com/json-iterator/go"
)

func main() {
	m := map[string]interface{}{
		"3": 3,
		"1": 1,
		"2": 2,
	}
	json := jsoniter.ConfigCompatibleWithStandardLibrary
	b, err := json.Marshal(m)
	fmt.Printf(">>> json : %#v\n", b)
	fmt.Printf(">>> err : %#v\n", err)
}

I use the demo 100% Compatibility section in official site

The line Json.Marshal(m) caused error:

unexpected fault address 0xffffffffffffffff
fatal error: fault
[signal 0xc0000005 code=0x0 addr=0xffffffffffffffff pc=0xccf85f]

goroutine 1 [running]:
runtime.throw({0xd94533?, 0x270e7a7b9e8?})
        C:/Program Files/Go/src/runtime/panic.go:1047 +0x65 fp=0xc000109b48 sp=0xc000109b18 pc=0xca6925
runtime.sigpanic()
        C:/Program Files/Go/src/runtime/signal_windows.go:261 +0x125 fp=0xc000109b90 sp=0xc000109b48 pc=0xcb9dc5
aeshashbody()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1366 +0x39f fp=0xc000109b98 sp=0xc000109b90 pc=0xccf85f
runtime.mapiternext(0xc000028480)
        C:/Program Files/Go/src/runtime/map.go:936 +0x2eb fp=0xc000109c08 sp=0xc000109b98 pc=0xc7f4cb
runtime.mapiterinit(0xc0000269c0?, 0x0?, 0xa?)
        C:/Program Files/Go/src/runtime/map.go:863 +0x236 fp=0xc000109c28 sp=0xc000109c08 pc=0xc7f196
reflect.mapiterinit(0xd72640?, 0xc0000269c8?, 0xc000109d40?)
        C:/Program Files/Go/src/runtime/map.go:1375 +0x19 fp=0xc000109c50 sp=0xc000109c28 pc=0xcccdd9
github.com/modern-go/reflect2.(*UnsafeMapType).UnsafeIterate(...)
        C:/Users/xxx/go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/unsafe_map.go:112
github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc000101890, 0xc00000a270, 0xc000060060)
        C:/Users/xxx/go/pkg/mod/github.com/json-iterator/go@v1.1.11/reflect_map.go:291 +0x236 fp=0xc000109dc0 sp=0xc000109c50 pc=0xd4ae56
github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc000052af0, 0xc000101650, 0xc000028480?)
        C:/Users/xxx/go/pkg/mod/github.com/json-iterator/go@v1.1.11/reflect.go:219 +0x82 fp=0xc000109df8 sp=0xc000109dc0 pc=0xd430e2
github.com/json-iterator/go.(*Stream).WriteVal(0xc000060060, {0xd74860, 0xc000101650})
        C:/Users/xxx/go/pkg/mod/github.com/json-iterator/go@v1.1.11/reflect.go:98 +0x166 fp=0xc000109e68 sp=0xc000109df8 pc=0xd42406
github.com/json-iterator/go.(*frozenConfig).Marshal(0xc0000001e0, {0xd74860, 0xc000101650})
        C:/Users/xxx/go/pkg/mod/github.com/json-iterator/go@v1.1.11/config.go:299 +0xc9 fp=0xc000109f00 sp=0xc000109e68 pc=0xd3aba9
main.main()
        D:/dev/__xxx/semi-automatic-assistant/wails_version/main.go:16 +0x127 fp=0xc000109f80 sp=0xc000109f00 pc=0xd61287
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:250 +0x1fe fp=0xc000109fe0 sp=0xc000109f80 pc=0xca905e
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000109fe8 sp=0xc000109fe0 pc=0xcd25c1

go version go1.19.5 windows/amd64

@newproplus
Copy link
Author

go version go1.20.1 windows/amd64 has the same issue

@newproplus
Copy link
Author

package main

import (
	"fmt"

	// jsoniter "github.com/json-iterator/go"
	"encoding/json"
)

func main() {
	m := map[string]interface{}{
		"3": 3,
		"1": 1,
		"2": 2,
	}
	// json := jsoniter.ConfigCompatibleWithStandardLibrary
	// json := jsoniter.ConfigDefault
	b, err := json.Marshal(m)
	fmt.Printf(">>> json : %#v\n", b)
	fmt.Printf(">>> err : %#v\n", err)
}

If I use "encoding/json", it works

@fraenky8
Copy link

fraenky8 commented Feb 21, 2023

Same here but for regular Marshal and MarshalIndent: https://go.dev/play/p/c-ddkeoZ7Dr

Go: go version go1.20.1 darwin/amd64

MacOS Ventura 13.2.1: Darwin xxx.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64

package main

import (
	"fmt"
	"math"

	jsoniter "github.com/json-iterator/go"
)

const (
	maxFloat64 = float64(math.MaxInt64)
)

func main() {
	json := jsoniter.ConfigCompatibleWithStandardLibrary

	m := map[string]interface{}{
		"test":         42,
		"max_int64":    math.MaxInt64,
		"max_float64":  math.MaxFloat64,
		"my_max_float": maxFloat64,
	}

	b, err := json.MarshalIndent(m, "", "  ")
	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))
}

Sharing stacktrace for debugging:

unexpected fault address 0xb01dfacedebac1e
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x105ec1f]

goroutine 1 [running]:
runtime.throw({0x1125b45?, 0xc00010f440?})
	/usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0xc000108ad8 sp=0xc000108aa8 pc=0x1031cdd
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:851 +0x28a fp=0xc000108b38 sp=0xc000108ad8 pc=0x1047b6a
aeshashbody()
	/usr/local/go/src/runtime/asm_amd64.s:1370 +0x39f fp=0xc000108b40 sp=0xc000108b38 pc=0x105ec1f
runtime.mapiternext(0xc000122400)
	/usr/local/go/src/runtime/map.go:936 +0x2eb fp=0xc000108bb0 sp=0xc000108b40 pc=0x100ee6b
runtime.mapiterinit(0x1112160?, 0xc000108c10?, 0x1012865?)
	/usr/local/go/src/runtime/map.go:863 +0x236 fp=0xc000108bd0 sp=0xc000108bb0 pc=0x100eb36
reflect.mapiterinit(0x1212460?, 0xc000114f70?, 0x0?)
	/usr/local/go/src/runtime/map.go:1375 +0x19 fp=0xc000108bf8 sp=0xc000108bd0 pc=0x105c659
github.com/modern-go/reflect2.(*UnsafeMapType).UnsafeIterate(...)
	/Users/user/Coding/Go/pkg/mod/github.com/modern-go/reflect2@v1.0.1/unsafe_map.go:112
github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc00010f4d0, 0xc00011c270, 0xc00011e120)
	/Users/user/Coding/Go/src/github.com/fraenky8/jsoniter-go/reflect_map.go:291 +0x225 fp=0xc000108d68 sp=0xc000108bf8 pc=0x10dc6a5
github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc00010c8a0, 0xc00010f170, 0xc000122400?)
	/Users/user/Coding/Go/src/github.com/fraenky8/jsoniter-go/reflect.go:219 +0x82 fp=0xc000108da0 sp=0xc000108d68 pc=0x10d4be2
github.com/json-iterator/go.(*Stream).WriteVal(0xc00011e120, {0x1105140, 0xc00010f170})
	/Users/user/Coding/Go/src/github.com/fraenky8/jsoniter-go/reflect.go:98 +0x158 fp=0xc000108e10 sp=0xc000108da0 pc=0x10d3ef8
github.com/json-iterator/go.(*frozenConfig).Marshal(0xc0001361e0, {0x1105140, 0xc00010f170})
	/Users/user/Coding/Go/src/github.com/fraenky8/jsoniter-go/config.go:299 +0xc9 fp=0xc000108ea8 sp=0xc000108e10 pc=0x10cc729
github.com/json-iterator/go.(*frozenConfig).MarshalIndent(0xc0001360a0, {0x1105140, 0xc00010f170}, {0x0?, 0x60?}, {0x112582a, 0x2})
	/Users/user/Coding/Go/src/github.com/fraenky8/jsoniter-go/config.go:320 +0x131 fp=0xc000108f20 sp=0xc000108ea8 pc=0x10cca11
main.main()
	/Users/user/Coding/Go/src/github.com/fraenky8/playground/cmd/json/main.go:332 +0x138 fp=0xc000108f80 sp=0xc000108f20 pc=0x10f2738
runtime.main()
	/usr/local/go/src/runtime/proc.go:250 +0x207 fp=0xc000108fe0 sp=0xc000108f80 pc=0x1034567
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000108fe8 sp=0xc000108fe0 pc=0x1061701

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc00003efb0 sp=0xc00003ef90 pc=0x1034996
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:387
runtime.forcegchelper()
	/usr/local/go/src/runtime/proc.go:305 +0xb0 fp=0xc00003efe0 sp=0xc00003efb0 pc=0x10347d0
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00003efe8 sp=0xc00003efe0 pc=0x1061701
created by runtime.init.6
	/usr/local/go/src/runtime/proc.go:293 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc00003f780 sp=0xc00003f760 pc=0x1034996
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:387
runtime.bgsweep(0x0?)
	/usr/local/go/src/runtime/mgcsweep.go:278 +0x8e fp=0xc00003f7c8 sp=0xc00003f780 pc=0x1021f4e
runtime.gcenable.func1()
	/usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc00003f7e0 sp=0xc00003f7c8 pc=0x10173e6
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00003f7e8 sp=0xc00003f7e0 pc=0x1061701
created by runtime.gcenable
	/usr/local/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc000024070?, 0x114c730?, 0x1?, 0x0?, 0x0?)
	/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc00003ff70 sp=0xc00003ff50 pc=0x1034996
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:387
runtime.(*scavengerState).park(0x1212020)
	/usr/local/go/src/runtime/mgcscavenge.go:400 +0x53 fp=0xc00003ffa0 sp=0xc00003ff70 pc=0x101fe53
runtime.bgscavenge(0x0?)
	/usr/local/go/src/runtime/mgcscavenge.go:628 +0x45 fp=0xc00003ffc8 sp=0xc00003ffa0 pc=0x1020425
runtime.gcenable.func2()
	/usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc00003ffe0 sp=0xc00003ffc8 pc=0x1017386
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00003ffe8 sp=0xc00003ffe0 pc=0x1061701
created by runtime.gcenable
	/usr/local/go/src/runtime/mgc.go:179 +0xaa

goroutine 17 [finalizer wait]:
runtime.gopark(0x1034d12?, 0x17153c8?, 0x0?, 0x0?, 0xc00003e770?)
	/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc00003e628 sp=0xc00003e608 pc=0x1034996
runtime.runfinq()
	/usr/local/go/src/runtime/mfinal.go:193 +0x107 fp=0xc00003e7e0 sp=0xc00003e628 pc=0x1016427
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc00003e7e8 sp=0xc00003e7e0 pc=0x1061701
created by runtime.createfing
	/usr/local/go/src/runtime/mfinal.go:163 +0x45
exit status 2

@fahimbagar
Copy link

fahimbagar commented Feb 21, 2023

The same issue happens since last year, modern-go/reflect2#26
Seems like can be fixed by upgrading the reflect2 version to 1.0.2. Latest jsoniter has the version already.

References:

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

3 participants