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

it will panic fault when Marshal map (go version 1.18) #608

Open
goeoeo opened this issue Mar 17, 2022 · 11 comments
Open

it will panic fault when Marshal map (go version 1.18) #608

goeoeo opened this issue Mar 17, 2022 · 11 comments

Comments

@goeoeo
Copy link

goeoeo commented Mar 17, 2022

func TestMarshal(t *testing.T) {
m := make(map[string]string)
m["a"] = "sss&aaa"
s, _ := jsoniter.Marshal(m)
fmt.Println(string(s))
}

//output
=== RUN TestMarshal
unexpected fault address 0x0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0x46327f]

goroutine 6 [running]:
runtime.throw({0x5828e5?, 0xc000078ce8?})
/usr/local/go/src/runtime/panic.go:992 +0x71 fp=0xc000078c18 sp=0xc000078be8 pc=0x434fd1
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:825 +0x305 fp=0xc000078c68 sp=0xc000078c18 pc=0x44afc5

@goeoeo goeoeo changed the title it will panic fault when Marshal map it will panic fault when Marshal map (go version 1.18) Mar 17, 2022
@tamalsaha
Copy link

tamalsaha commented Mar 17, 2022

We are also seeing the same issue. Here is a stack trace:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xb08a94]

goroutine 38 [running]:
testing.tRunner.func1.2({0x1e6eba0, 0x2dd46a0})
	/usr/local/go/src/testing/testing.go:1389 +0x366
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1392 +0x5d2
panic({0x1e6eba0, 0x2dd46a0})
	/usr/local/go/src/runtime/panic.go:844 +0x258
github.com/json-iterator/go.(*Stream).WriteStringWithHTMLEscaped(0xc00015c120, {0x8, 0x8})
	/src/vendor/github.com/json-iterator/go/stream_str.go:227 +0x134
github.com/json-iterator/go.(*htmlEscapedStringEncoder).Encode(0xc0005d7700?, 0x1e646e0, 0x41?)
	/src/vendor/github.com/json-iterator/go/config.go:263 +0x65
github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0001d2720, 0x1e1097e?, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0xad
github.com/json-iterator/go.(*structEncoder).Encode(0xc0001d2fc0, 0xc0004f7640?, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0xd65
github.com/json-iterator/go.(*sliceEncoder).Encode(0xc0000151d0, 0xc0000f1240, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_slice.go:38 +0x7cf
github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc000351170, 0xc0000f11a0?, 0x32?)
	/src/vendor/github.com/json-iterator/go/reflect.go:[332](https://github.com/kubeguard/guard/runs/5581979741?check_suite_focus=true#step:7:332) +0x58
github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0001e10e0, 0x1eba61b?, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0xad
github.com/json-iterator/go.(*structEncoder).Encode(0xc0001e11d0, 0xc0000f1180?, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0xd65
github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc000248510, 0x1e35815?, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0xad
github.com/json-iterator/go.(*structEncoder).Encode(0xc000248600, 0x233a6b8?, 0xc00015c120)
	/src/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0xd65
github.com/json-iterator/go.(*Stream).WriteVal(0xc00015c120, {0x1f2f840, 0xc0000f1180})
	/src/vendor/github.com/json-iterator/go/reflect.go:98 +0x1f8
github.com/json-iterator/go.(*Encoder).Encode(0xc00011c060, {0x1f2f840, 0xc0000f1180})
	/src/vendor/github.com/json-iterator/go/adapter.go:127 +0x65
go.kubeguard.dev/guard/server.TestServeHTTP(0xc0001e36c0)
	/src/server/handler_test.go:85 +0x91c
testing.tRunner(0xc0001e36c0, 0x210cdc8)
	/usr/local/go/src/testing/testing.go:1439 +0x214
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1486 +0x725

https://github.com/kubeguard/guard/runs/5581979741?check_suite_focus=true

@tamalsaha
Copy link

tamalsaha commented Mar 17, 2022

This was fixed in golang/go#48238 (comment)

After updating the versions, our tests are passing. Thanks!

@flarco
Copy link

flarco commented Mar 18, 2022

Seeing this as well.

@fuxingZhang
Copy link

fuxingZhang commented Mar 21, 2022

json-iterator <=1.1.11 + go 1.17 ok
json-iterator <=1.1.11 + go 1.18 bug
json-iterator >=1.1.12 + go 1.18 ok

solution

go get -u github.com/json-iterator/go

@feiquan123
Copy link

same fault in my project 😔

matthchr added a commit to matthchr/azure-service-operator that referenced this issue Apr 11, 2022
matthchr added a commit to matthchr/azure-service-operator that referenced this issue Apr 11, 2022
matthchr added a commit to Azure/azure-service-operator that referenced this issue Apr 11, 2022
@toby-wang
Copy link

toby-wang commented Jul 22, 2022

our service json-iterator=1.1.12 and go=1.18, but panic still occurs occasionally.

	goroutine panic err:runtime error: invalid memory address or nil pointer dereference trace:goroutine 141798238 [running]:
runtime/debug.Stack()
	golang/go/src/runtime/debug/stack.go:24 +0x65
gitlab.myteksi.net/gophers/go/food/common/concurrencyutils.defaultGo.func1.1()
	/go/src/gitlab.myteksi.net/gophers/go/food/common/concurrencyutils/concurrencyutils.go:61 +0x277
panic({0x385af60, 0x75d45d0})
	golang/go/src/runtime/panic.go:838 +0x207
github.com/json-iterator/go.(*Stream).WriteStringWithHTMLEscaped(0xc0624dafc0, {0x0, 0x20})
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/stream_str.go:227 +0xbf
github.com/json-iterator/go.(*htmlEscapedStringEncoder).Encode(0x389b340?, 0x1?, 0xc0624dafd8?)
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/config.go:263 +0x29
github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0449ed0b0, 0x34744bd?, 0xc0624dafc0)
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/json-iterator/go.(*structEncoder).Encode(0xc0449ed110, 0x0?, 0xc0624dafc0)
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x765
github.com/json-iterator/go.(*OptionalEncoder).Encode(0xc01f8c1b58?, 0x40d085?, 0x390ada0?)
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/reflect_optional.go:70 +0xa4
github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc00b155d20, 0xc0495b01e0, 0xc01f8c1ba8?)
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/reflect.go:219 +0x82
github.com/json-iterator/go.(*Stream).WriteVal(0xc0624dafc0, {0x3573c00, 0xc0495b01e0})
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/reflect.go:98 +0x158
github.com/json-iterator/go.(*frozenConfig).Marshal(0xc000137540, {0x3573c00, 0xc0495b01e0})
	/go/src/gitlab.myteksi.net/gophers/go/vendor/github.com/json-iterator/go/config.go:299 +0xc9
gitlab.myteksi.net/gophers/go/food/common/encoding/json.Marshal(...)
	/go/src/gitlab.myteksi.net/gophers/go/food/common/encoding/json/json.go:30
gitlab.myteksi.net/gophers/go/food/mart-api/common/redis.SetAsPipeline({0x4be0ae0, 0xc085e4e450}, {0xc071f48c00, 0x1, 0x1}, {0x35b85e0?, 0xc06ee7b608?})
	/go/src/gitlab.myteksi.net/gophers/go/food/mart-api/common/redis/client.go:346 +0x510
gitlab.myteksi.net/gophers/go/food/mart-api/common/redis.glob..func7({0x4be0ae0, _}, {0x152d13c, {0xc005f68f60, 0xf}, 0x4008fceeb9b2fdd6, 0x40595e13ac206bc5, {0x0, 0x0}, {0x41731ea, ...}, ...}, ...)

@shahbazn
Copy link

shahbazn commented Sep 24, 2022

json-iterator=1.1.12 and go=1.19 -> works
json-iterator=1.1.11 and go=1.19 -> bug

@FarmerChillax
Copy link

go version go1.19.1 darwin/arm64 and json-iterator=1.1.12 same this bug

@spade69
Copy link

spade69 commented Apr 25, 2023

go version 1.20 and json-iterator = 1.1.11 occurs, but json-iterator=1.1.12 fixed it .

@purebluesong
Copy link

need to update reflect2:
golang/go#48238 (comment)

@oldthreefeng
Copy link

go get -u github.com/json-iterator/go

solution for me.

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