We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hey @goccy,
I've run the following test:
package main import ( "strings" "github.com/goccy/go-yaml" "gopkg.in/go-playground/validator.v9" ) type Person struct { Name string `yaml:"name" validate:"required"` Age int `yaml:"age" validate:"gte=0,lt=120"` Addr *PersonAddress `yaml:"addr" validate:"required,dive,required"` } type PersonAddress struct { Number string `yaml:"number" validate:"required"` State string `yaml:"state" validate:"required"` } func main() { yml := ` name: itai age: 10 addr: number: seven ` // missing State validate := validator.New() dec := yaml.NewDecoder( strings.NewReader(yml), yaml.Validator(validate), ) var v Person err := dec.Decode(&v) if err == nil { panic("expected error") } }
got the following crash log:
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x10effb2] goroutine 1 [running]: github.com/goccy/go-yaml.(*Decoder).decodeStruct(0xc0001fe000, 0x11b2480, 0xc0000a9fc0, 0x199, 0x1210c20, 0xc000105a80, 0x28, 0x11aa560) /Users/itai/work/go-yaml/decode.go:855 +0x1b12 github.com/goccy/go-yaml.(*Decoder).decodeValue(0xc0001fe000, 0x11b2480, 0xc0000a9fc0, 0x199, 0x1210c20, 0xc000105a80, 0x0, 0x2a) /Users/itai/work/go-yaml/decode.go:473 +0x1b0a github.com/goccy/go-yaml.(*Decoder).decode(0xc0001fe000, 0x1189e00, 0xc0000a9fc0, 0x16, 0x1189e00, 0x1337a20) /Users/itai/work/go-yaml/decode.go:1243 +0xd2 github.com/goccy/go-yaml.(*Decoder).Decode(0xc0001fe000, 0x1189e00, 0xc0000a9fc0, 0x1006cbf, 0xc00008e058) /Users/itai/work/go-yaml/decode.go:1272 +0x272 main.main() /Users/itati/work/go-yaml/cmd/validate/cmd.go:34 +0x1f6 exit status 2 shell returned 1
It seems that structFieldMap doesn't contain "State" fieldName, so we crash on null pointer deref (structField.RenderName)
structFieldMap
fieldName
structField := structFieldMap[fieldName] node, exists := keyToNodeMap[structField.RenderName]
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Hey @goccy,
I've run the following test:
got the following crash log:
It seems that
structFieldMap
doesn't contain "State"fieldName
, so we crash on null pointer deref (structField.RenderName)The text was updated successfully, but these errors were encountered: