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

Nil pointer dereference marshaling jsonschema.List #537

Open
lzap opened this issue Feb 19, 2025 · 0 comments
Open

Nil pointer dereference marshaling jsonschema.List #537

lzap opened this issue Feb 19, 2025 · 0 comments

Comments

@lzap
Copy link

lzap commented Feb 19, 2025

Reproducer: https://go.dev/play/p/8dL6bXM9IJC (times out on the playground unfortunately)

package main

import (
	"encoding/json"

	gojson "github.com/goccy/go-json"
	"github.com/kaptinlin/jsonschema"
)

var payload = `{
  "valid": false,
  "evaluationPath": "",
  "schemaLocation": "",
  "instanceLocation": "",
  "annotations": {
    "description": "Blueprint type prototype\n\nThis is just a brief example of a common blueprint structure. Just few fields\nwere selected to demonstrate the JSON schema."
  },
  "errors": {
    "properties": "Properties 'registration', 'network' do not match their schemas",
    "required": "Required properties 'registration', 'network' are missing"
  },
  "details": [
    {
      "valid": false,
      "evaluationPath": "/properties/registration",
      "schemaLocation": "https://github.com/lzap/common-blueprint-example/blueprint#/properties/registration",
      "instanceLocation": "/registration",
      "annotations": {
        "description": "Registration details"
      },
      "errors": {
        "type": "Value is null but should be object"
      }
    },
    {
      "valid": false,
      "evaluationPath": "/properties/network",
      "schemaLocation": "https://github.com/lzap/common-blueprint-example/blueprint#/properties/network",
      "instanceLocation": "/network",
      "annotations": {
        "description": "Networking details"
      },
      "errors": {
        "type": "Value is null but should be object"
      }
    },
    {
      "valid": true,
      "evaluationPath": "/properties/name",
      "schemaLocation": "https://github.com/lzap/common-blueprint-example/blueprint#/properties/name",
      "instanceLocation": "/name",
      "annotations": {
        "description": "Name of the blueprint"
      }
    }
  ]
}
`

func main() {
	var list jsonschema.List
	err := json.Unmarshal([]byte(payload), &list)
	if err != nil {
		panic(err)
	}

	_, err = gojson.MarshalIndent(list, "", "  ")
	if err != nil {
		panic(err)
	}
}

The error:

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

goroutine 1 [running]:
github.com/goccy/go-json/internal/encoder/vm_indent.Run(0xc0000a1860, {0xc00009a800, 0x30f, 0x400}, 0xc0000c4460)
	/home/lzap/go/pkg/mod/github.com/goccy/go-json@v0.10.5/internal/encoder/vm_indent/vm.go:425 +0x683
github.com/goccy/go-json.encodeRunIndentCode(0xc0000a1860, {0xc00009a800, 0x0, 0x400}, 0xc0000c4460, {0x0, 0x0}, {0x7eacf7, 0x2})
	/home/lzap/go/pkg/mod/github.com/goccy/go-json@v0.10.5/encode.go:325 +0x545
github.com/goccy/go-json.encodeIndent(0xc0000a1860, {0x7d80a0, 0xc000084420}, {0x0, 0x0}, {0x7eacf7, 0x2})
	/home/lzap/go/pkg/mod/github.com/goccy/go-json@v0.10.5/encode.go:288 +0x265
github.com/goccy/go-json.marshalIndent({0x7d80a0, 0xc000084420}, {0x0, 0x0}, {0x7eacf7, 0x2}, {0x0, 0x0, 0x0})
	/home/lzap/go/pkg/mod/github.com/goccy/go-json@v0.10.5/encode.go:201 +0x1bd
github.com/goccy/go-json.MarshalIndentWithOption({0x7d80a0, 0xc000084420}, {0x0, 0x0}, {0x7eacf7, 0x2}, {0x0, 0x0, 0x0})
	/home/lzap/go/pkg/mod/github.com/goccy/go-json@v0.10.5/json.go:197 +0xdf
github.com/goccy/go-json.MarshalIndent({0x7d80a0, 0xc000084420}, {0x0, 0x0}, {0x7eacf7, 0x2})
	/home/lzap/go/pkg/mod/github.com/goccy/go-json@v0.10.5/json.go:192 +0xb8
main.main()
	/home/lzap/common-blueprint-example/cmd/validate-schema/main.go:67 +0x13c

Thanks for help.

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