Skip to content

mapassign_faststr: panic: runtime error: invalid memory address or nil pointer dereference #282

@miktwon

Description

@miktwon

Hey. GLHF ^_^

go version go1.17 linux/amd64

My case:

package main

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

var J = []byte(`{
  "a": {},
  "b": {},
  "c": {},
  "d": {},
  "e": {},
  "f": {},
  "g": {},
  "h": {
    "m": "1"
  },
  "i": {}
}`)

type T0 map[string]T2

type T2 struct {
	F0 string `json:"m"`
	F1 T3
}

type T3 struct {
	F0 string
	F1 T4
}

type T4 struct {
	F0 string
	F1 string
	F2 string
	F3 string
	F4 string
	F5 string
	F6 int
}

func main() {
	json.Unmarshal(J, &T0{})
}

Out:

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

goroutine 1 [running]:
github.com/goccy/go-json/internal/decoder.(*mapDecoder).mapassign(0xc0000b6120, 0xc0000e6200, 0x0, 0x1, 0xc00009e430)
	/home/go/pkg/mod/github.com/goccy/go-json@v0.7.7/internal/decoder/map.go:49 +0x3c
github.com/goccy/go-json/internal/decoder.(*mapDecoder).Decode(0xc0000b6120, 0xc0000e6200, 0xc0000a0150, 0x5703c0, 0xc0000b4028)
	/home/go/pkg/mod/github.com/goccy/go-json@v0.7.7/internal/decoder/map.go:161 +0x550
github.com/goccy/go-json.unmarshal({0x5703c0, 0xc00009af70, 0x405759}, {0x4b7f80, 0xc0000b4028}, {0x0, 0x0, 0x4ba380})
	/home/go/pkg/mod/github.com/goccy/go-json@v0.7.7/decode.go:47 +0x187
github.com/goccy/go-json.Unmarshal(...)
	/home/go/pkg/mod/github.com/goccy/go-json@v0.7.7/json.go:276
main.main()
	oops/main.go:44 +0x79
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions