Skip to content

nil pointer panic when Unmarshal with a empty file #508

Closed
@hanxiatu-fc

Description

@hanxiatu-fc
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x40 pc=0x595a84]

goroutine 1 [running]:
github.com/json-iterator/go.(*Iterator).ReadVal(0xc00016c000, 0x0, 0x0)
	C:/Users/f00515581/go/pkg/mod/github.com/json-iterator/[email protected]/reflect.go:68 +0x2d4
github.com/json-iterator/go.(*frozenConfig).Unmarshal(0xc000058140, 0x2c270000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	C:/Users/f00515581/go/pkg/mod/github.com/json-iterator/[email protected]/config.go:348 +0xd6
github.com/json-iterator/go.Unmarshal(...)
	C:/Users/f00515581/go/pkg/mod/github.com/json-iterator/[email protected]/adapter.go:16
jsoniter.Fuzz(0x2c270000, 0x0, 0x0, 0x6b0)
	D:/workspace/go/fuzz_test/jsoniter/fuzz.go:19 +0x18b
go-fuzz-dep.Main(0xc000119f70, 0x1, 0x1)
	go-fuzz-dep/main.go:36 +0x1b4
main.main()
	jsoniter/go.fuzz.main/main.go:15 +0x59
exit status 2

We can reproduce the problem just by call json.Unmarshal(data, nil)

in github.com/json-iterator/[email protected]/reflect.go

67		typ := reflect2.TypeOf(obj)    // when we call json.Unmarshal(anydata, nil), obj is nil, so typ is nil
68		if typ.Kind() != reflect.Ptr { // nil pointer dereference on typ

How did I find the problem?

I refer to the test cases and test corpus for std json in the go-fuzz project to test json-iterator.

see : https://github.com/dvyukov/go-fuzz-corpus/tree/master/json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions