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

Marshalling exception "slice bounds out of range" #526

Open
fedulovivan opened this issue Nov 4, 2024 · 0 comments
Open

Marshalling exception "slice bounds out of range" #526

fedulovivan opened this issue Nov 4, 2024 · 0 comments

Comments

@fedulovivan
Copy link

Recently I have switched to go-json to try it out and noticed the marshalling of same data structure with go-json comparing with encoding/json causes a panic runtime error: slice bounds out of range [206158430215:52]
Go version go version go1.22.5 darwin/arm64 (reproducble also on x86 in docker)
Also noticed there is no panic if I replace tag json:"-" with json:"id" in Condition struct below.
Minimal code block to reporoduce:

package main
import (
	"github.com/goccy/go-json"
)
type CondFn byte
type Args map[string]any
type Rule struct {
	Id        int       `json:"id"`
	Disabled  bool      `json:"disabled,omitempty"`
	Name      string    `json:"name,omitempty"`
	Condition Condition `json:"condition,omitempty"`
}
type Condition struct {
	Id     int         `json:"-"`
	Fn     CondFn      `json:"fn,omitempty"`
	Args   Args        `json:"args,omitempty"`
	Nested []Condition `json:"nested,omitempty"`
}
func main() {
	rule := Rule{
		Condition: Condition{
			Nested: []Condition{
				{
					Args: Args{
						"Value": 111,
					},
				},
			},
		},
	}
	_, _ = json.Marshal(rule)
}

Result:

~/Desktop/Projects/mhz19-go (main*) » go run repro.go                                                                                                                                               ivanf@mbp2021
panic: runtime error: slice bounds out of range [206158430215:52]

goroutine 1 [running]:
github.com/goccy/go-json/internal/encoder/vm.Run(0x1400012c750, {0x14000164000?, 0x0?, 0x400?}, 0x14000160070?)
	/Users/ivanf/go/pkg/mod/github.com/goccy/[email protected]/internal/encoder/vm/vm.go:440 +0x222b4
github.com/goccy/go-json.encodeRunCode(0x1400012c750?, {0x14000164000?, 0x1010d2920?, 0x14000118d90?}, 0x1400012a040?)
	/Users/ivanf/go/pkg/mod/github.com/goccy/[email protected]/encode.go:310 +0x64
github.com/goccy/go-json.encode(0x1400012c750, {0x100f922a0, 0x1400010e0a0})
	/Users/ivanf/go/pkg/mod/github.com/goccy/[email protected]/encode.go:235 +0x204
github.com/goccy/go-json.marshal({0x100f922a0, 0x1400010e0a0}, {0x0, 0x0, 0x14000118e01?})
	/Users/ivanf/go/pkg/mod/github.com/goccy/[email protected]/encode.go:150 +0xbc
github.com/goccy/go-json.MarshalWithOption(...)
	/Users/ivanf/go/pkg/mod/github.com/goccy/[email protected]/json.go:185
github.com/goccy/go-json.Marshal({0x100f922a0?, 0x1400010e0a0?})
	/Users/ivanf/go/pkg/mod/github.com/goccy/[email protected]/json.go:170 +0x30
main.main()
	/Users/ivanf/Desktop/Projects/mhz19-go/repro.go:34 +0xe8
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