Skip to content

Panic in Go Application When Marshaling Structs #519

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

Open
aleksei-u opened this issue Aug 8, 2024 · 1 comment
Open

Panic in Go Application When Marshaling Structs #519

aleksei-u opened this issue Aug 8, 2024 · 1 comment

Comments

@aleksei-u
Copy link

Our application panics when trying to marshal a struct using the github.com/goccy/go-json package. The issue seems to occur when attempting to serialize a struct.

Steps to Reproduce:
Create a new Go file with the following code:

package main

import (
	"fmt"

	"github.com/goccy/go-json"
)

type Body struct {
	Payload *Detail `json:"p,omitempty"`
}

type Detail struct {
	I Item `json:"i"`
}

type Item struct {
	A string `json:"a"`
	B string `json:"b,omitempty"`
}

func main() {
	b, err := json.Marshal(Body{
		Payload: &Detail{
			I: Item{
				A: "a",
				B: "b",
			},
		},
	})
	fmt.Println(err)
	fmt.Println(string(b))
}

Run the program using the go run command.

Expected Result:
The program should output the JSON string without any errors, similar to: {"p":{"i":{"a":"a","b":"b"}}}

Actual Result:
The program panics and does not output the expected JSON string.

Additional Information:
go.mod

module my.com/app

go 1.22.5

require github.com/goccy/go-json v0.10.3
goroutine 1 gp=0xc0000061c0 m=0 mp=0x4cee8c0 [running]:
runtime.throw({0x4bb6cef?, 0x0?})
/usr/local/go/src/runtime/panic.go:1023 +0x5c fp=0xc0000278d0 sp=0xc0000278a0 pc=0x4ad121c
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:895 +0x285 fp=0xc000027930 sp=0xc0000278d0 pc=0x4ae7565
github.com/goccy/go-json/internal/encoder.appendNormalizedHTMLString({0xc00012c000?, 0x0?, 0x0?}, {0x3d3a3c4d29306061, 0x2829202c29694c5f})
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/string.go:73 +0xe34 fp=0xc0000279f8 sp=0xc000027930 pc=0x4b5b534
github.com/goccy/go-json/internal/encoder.AppendString(0x0?, {0xc00012c000?, 0x0?, 0x0?}, {0x3d3a3c4d29306061?, 0x0?})
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/string.go:52 +0x45 fp=0xc000027a30 sp=0xc0000279f8 pc=0x4b5a645
github.com/goccy/go-json/internal/encoder/vm.Run(0xc000104750, {0xc00012c000?, 0x0?, 0x400?}, 0xc00012a070?)
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/vm.go:1718 +0x4db1 fp=0xc000029d88 sp=0xc000027a30 pc=0x4b949f1
github.com/goccy/go-json.encodeRunCode(0xc000104750?, {0xc00012c000?, 0xc000186dc0?, 0xc000102040?}, 0xc00012c400?)
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/encode.go:310 +0x56 fp=0xc000029dc0 sp=0xc000029d88 pc=0x4bb64b6
github.com/goccy/go-json.encode(0xc000104750, {0x4c07140, 0xc00007a060})
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/encode.go:235 +0x205 fp=0xc000029e40 sp=0xc000029dc0 pc=0x4bb63c5
github.com/goccy/go-json.marshal({0x4c07140, 0xc00007a060}, {0x0, 0x0, 0x1?})
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/encode.go:150 +0xb9 fp=0xc000029ea0 sp=0xc000029e40 pc=0x4bb60b9
github.com/goccy/go-json.MarshalWithOption(...)
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/json.go:185
github.com/goccy/go-json.Marshal({0x4c07140?, 0xc00007a060?})
/Users/al/go/pkg/mod/github.com/goccy/[email protected]/json.go:170 +0x25 fp=0xc000029ed8 sp=0xc000029ea0 pc=0x4bb6525
main.main()
/Users/al/src/test/main.go:25 +0x90 fp=0xc000029f50 sp=0xc000029ed8 pc=0x4bb66d0
runtime.main()
/usr/local/go/src/runtime/proc.go:271 +0x29d fp=0xc000029fe0 sp=0xc000029f50 pc=0x4ad3c7d
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc000029fe8 sp=0xc000029fe0 pc=0x4b01e81

goroutine 2 gp=0xc000006700 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc00005efa8 sp=0xc00005ef88 pc=0x4ad40ae
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:408
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:326 +0xb3 fp=0xc00005efe0 sp=0xc00005efa8 pc=0x4ad3f33
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc00005efe8 sp=0xc00005efe0 pc=0x4b01e81
created by runtime.init.6 in goroutine 1
/usr/local/go/src/runtime/proc.go:314 +0x1a

goroutine 3 gp=0xc000006c40 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc00005f780 sp=0xc00005f760 pc=0x4ad40ae
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:408
runtime.bgsweep(0xc000078000)
/usr/local/go/src/runtime/mgcsweep.go:278 +0x94 fp=0xc00005f7c8 sp=0xc00005f780 pc=0x4ac0dd4
runtime.gcenable.gowrap1()
/usr/local/go/src/runtime/mgc.go:203 +0x25 fp=0xc00005f7e0 sp=0xc00005f7c8 pc=0x4ab5925
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc00005f7e8 sp=0xc00005f7e0 pc=0x4b01e81
created by runtime.gcenable in goroutine 1
/usr/local/go/src/runtime/mgc.go:203 +0x66

goroutine 4 gp=0xc000006e00 m=nil [GC scavenge wait]:
runtime.gopark(0xc000078000?, 0x4bf0f20?, 0x1?, 0x0?, 0xc000006e00?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc00005ff78 sp=0xc00005ff58 pc=0x4ad40ae
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:408
runtime.(*scavengerState).park(0x4cee160)
/usr/local/go/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc00005ffa8 sp=0xc00005ff78 pc=0x4abe7c9
runtime.bgscavenge(0xc000078000)
/usr/local/go/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc00005ffc8 sp=0xc00005ffa8 pc=0x4abed5c
runtime.gcenable.gowrap2()
/usr/local/go/src/runtime/mgc.go:204 +0x25 fp=0xc00005ffe0 sp=0xc00005ffc8 pc=0x4ab58c5
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc00005ffe8 sp=0xc00005ffe0 pc=0x4b01e81
created by runtime.gcenable in goroutine 1
/usr/local/go/src/runtime/mgc.go:204 +0xa5

goroutine 5 gp=0xc000007340 m=nil [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:402 +0xce fp=0xc000060620 sp=0xc000060600 pc=0x4ad40ae
runtime.runfinq()
/usr/local/go/src/runtime/mfinal.go:194 +0x107 fp=0xc0000607e0 sp=0xc000060620 pc=0x4ab4967
runtime.goexit({})
/usr/local/go/src/runtime/asm_amd64.s:1695 +0x1 fp=0xc0000607e8 sp=0xc0000607e0 pc=0x4b01e81
created by runtime.createfing in goroutine 1
/usr/local/go/src/runtime/mfinal.go:164 +0x3d
exit status 2
@aleksei-u
Copy link
Author

aleksei-u commented Apr 7, 2025

go version
go version go1.24.0 darwin/arm64
cat go.mod
module example.com/mod

go 1.24.0

require github.com/goccy/go-json v0.10.5
go run .
unexpected fault address 0x2c3c4d2928306061
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0x2c3c4d2928306061 pc=0x10467b708]

goroutine 1 gp=0x140000021c0 m=0 mp=0x1048261e0 [running]:
runtime.throw({0x1046cf280?, 0x0?})
	/usr/local/go/src/runtime/panic.go:1096 +0x38 fp=0x140001d4410 sp=0x140001d43e0 pc=0x1046192c8
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:939 +0x224 fp=0x140001d4470 sp=0x140001d4410 pc=0x10461aba4
github.com/goccy/go-json/internal/encoder.appendNormalizedHTMLString({0x140001b0000?, 0x0?, 0x14000022578?}, {0x2c3c4d2928306061, 0x2c2969794c5f3d31})
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/string.go:73 +0xbf8 fp=0x140001d4540 sp=0x140001d4480 pc=0x10467b708
github.com/goccy/go-json/internal/encoder.AppendString(0x0?, {0x140001b0000?, 0x0?, 0x0?}, {0x2c3c4d2928306061?, 0x0?})
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/string.go:52 +0x48 fp=0x140001d4580 sp=0x140001d4540 pc=0x10467aa68
github.com/goccy/go-json/internal/encoder/vm.Run(0x140001944e0, {0x140001b0000?, 0x0?, 0x400?}, 0x140001ae070?)
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/vm.go:1718 +0x4810 fp=0x140001d7d60 sp=0x140001d4580 pc=0x1046b00d0
github.com/goccy/go-json.encodeRunCode(0x140001944e0?, {0x140001b0000?, 0x10484b910?, 0x14000104db0?}, 0x14000190040?)
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/encode.go:310 +0x64 fp=0x140001d7da0 sp=0x140001d7d60 pc=0x1046ce8d4
github.com/goccy/go-json.encode(0x140001944e0, {0x10472b740, 0x140001960a0})
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/encode.go:235 +0x204 fp=0x140001d7e30 sp=0x140001d7da0 pc=0x1046ce7c4
github.com/goccy/go-json.marshal({0x10472b740, 0x140001960a0}, {0x0, 0x0, 0x104826101?})
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/encode.go:150 +0xb8 fp=0x140001d7e90 sp=0x140001d7e30 pc=0x1046ce4c8
github.com/goccy/go-json.MarshalWithOption(...)
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/json.go:185
github.com/goccy/go-json.Marshal({0x10472b740?, 0x140001960a0?})
	/Users/test-user/go/pkg/mod/github.com/goccy/[email protected]/json.go:170 +0x30 fp=0x140001d7ed0 sp=0x140001d7e90 pc=0x1046ce940
main.main()
	/Users/test-user/src/hr/go-service-template_test/main.go:23 +0x58 fp=0x140001d7f40 sp=0x140001d7ed0 pc=0x1046ceaa8
runtime.main()
	/usr/local/go/src/runtime/proc.go:283 +0x284 fp=0x140001d7fd0 sp=0x140001d7f40 pc=0x1045e8d74
runtime.goexit({})
	/usr/local/go/src/runtime/asm_arm64.s:1223 +0x4 fp=0x140001d7fd0 sp=0x140001d7fd0 pc=0x10461fa84

goroutine 17 gp=0x14000082380 m=nil [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/usr/local/go/src/runtime/proc.go:435 +0xc8 fp=0x14000058790 sp=0x14000058770 pc=0x1046193a8
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:441
runtime.forcegchelper()
	/usr/local/go/src/runtime/proc.go:348 +0xb8 fp=0x140000587d0 sp=0x14000058790 pc=0x1045e90c8
runtime.goexit({})
	/usr/local/go/src/runtime/asm_arm64.s:1223 +0x4 fp=0x140000587d0 sp=0x140000587d0 pc=0x10461fa84
created by runtime.init.7 in goroutine 1
	/usr/local/go/src/runtime/proc.go:336 +0x24

goroutine 18 gp=0x14000082540 m=nil [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/usr/local/go/src/runtime/proc.go:435 +0xc8 fp=0x14000058f60 sp=0x14000058f40 pc=0x1046193a8
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:441
runtime.bgsweep(0x14000090000)
	/usr/local/go/src/runtime/mgcsweep.go:276 +0xa0 fp=0x14000058fb0 sp=0x14000058f60 pc=0x1045d56a0
runtime.gcenable.gowrap1()
	/usr/local/go/src/runtime/mgc.go:204 +0x28 fp=0x14000058fd0 sp=0x14000058fb0 pc=0x1045c9808
runtime.goexit({})
	/usr/local/go/src/runtime/asm_arm64.s:1223 +0x4 fp=0x14000058fd0 sp=0x14000058fd0 pc=0x10461fa84
created by runtime.gcenable in goroutine 1
	/usr/local/go/src/runtime/mgc.go:204 +0x6c

goroutine 19 gp=0x14000082700 m=nil [GC scavenge wait]:
runtime.gopark(0x14000090000?, 0x10470f588?, 0x1?, 0x0?, 0x14000082700?)
	/usr/local/go/src/runtime/proc.go:435 +0xc8 fp=0x14000059760 sp=0x14000059740 pc=0x1046193a8
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:441
runtime.(*scavengerState).park(0x104825940)
	/usr/local/go/src/runtime/mgcscavenge.go:425 +0x5c fp=0x14000059790 sp=0x14000059760 pc=0x1045d31ac
runtime.bgscavenge(0x14000090000)
	/usr/local/go/src/runtime/mgcscavenge.go:653 +0x44 fp=0x140000597b0 sp=0x14000059790 pc=0x1045d36e4
runtime.gcenable.gowrap2()
	/usr/local/go/src/runtime/mgc.go:205 +0x28 fp=0x140000597d0 sp=0x140000597b0 pc=0x1045c97a8
runtime.goexit({})
	/usr/local/go/src/runtime/asm_arm64.s:1223 +0x4 fp=0x140000597d0 sp=0x140000597d0 pc=0x10461fa84
created by runtime.gcenable in goroutine 1
	/usr/local/go/src/runtime/mgc.go:205 +0xac

goroutine 33 gp=0x14000186000 m=nil [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/usr/local/go/src/runtime/proc.go:435 +0xc8 fp=0x1400018c590 sp=0x1400018c570 pc=0x1046193a8
runtime.runfinq()
	/usr/local/go/src/runtime/mfinal.go:196 +0x108 fp=0x1400018c7d0 sp=0x1400018c590 pc=0x1045c8808
runtime.goexit({})
	/usr/local/go/src/runtime/asm_arm64.s:1223 +0x4 fp=0x1400018c7d0 sp=0x1400018c7d0 pc=0x10461fa84
created by runtime.createfing in goroutine 1
	/usr/local/go/src/runtime/mfinal.go:166 +0x80
exit status 2

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

1 participant