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

Crash in searchKeys #178

Closed
p4zuu opened this issue Oct 18, 2019 · 0 comments
Closed

Crash in searchKeys #178

p4zuu opened this issue Oct 18, 2019 · 0 comments

Comments

@p4zuu
Copy link

p4zuu commented Oct 18, 2019

The following code makes a panic in searchKeys function:

package fuzz

import (
	"testing"

	"github.com/buger/jsonparser"
)

func TestFuzzCrasher(t *testing.T) {
	crasher := []byte(`{{{"":`)
	jsonparser.GetInt(crasher, "a", "b")
}

Here is the panic output

panic: runtime error: index out of range [2] with length 2

goroutine 1 [running]:
github.com/buger/jsonparser.searchKeys(0x4010000, 0x6, 0x6, 0xc000088e50, 0x2, 0x2, 0xffffffffffffffff)
	/Users/thomasleroy/Software/go/src/github.com/buger/jsonparser/parser.go:264 +0xef5
github.com/buger/jsonparser.internalGet(0x4010000, 0x6, 0x6, 0xc000088e50, 0x2, 0x2, 0x0, 0xc000000180, 0xc000088d70, 0x1031f50, ...)
	/Users/thomasleroy/Software/go/src/github.com/buger/jsonparser/parser.go:876 +0x3b5
github.com/buger/jsonparser.Get(0x4010000, 0x6, 0x6, 0xc000088e50, 0x2, 0x2, 0x1052a72, 0x10442bc, 0x1054ab0, 0xc000088e08, ...)
	/Users/thomasleroy/Software/go/src/github.com/buger/jsonparser/parser.go:870 +0x8b
github.com/buger/jsonparser.GetInt(0x4010000, 0x6, 0x6, 0xc000088e50, 0x2, 0x2, 0x1a22912800000000, 0x5daa1a76, 0xc000088e70)
	/Users/thomasleroy/Software/go/src/github.com/buger/jsonparser/parser.go:1140 +0x8b
_/Users/thomasleroy/Security/Fuzzing/Go-fuzz.Fuzz(0x4010000, 0x6, 0x6, 0x3)
	/Users/thomasleroy/Security/Fuzzing/Go-fuzz/jsonparser.go:8 +0x95
go-fuzz-dep.Main(0xc000088f48, 0x1, 0x1)
	go-fuzz-dep/main.go:36 +0x1ad
main.main()
	_/Users/thomasleroy/Security/Fuzzing/Go-fuzz/go.fuzz.main/main.go:15 +0x52
exit status 2

The function also crashes if you call GetInt(crasher, "a")

AllenX2018 added a commit to AllenX2018/jsonparser that referenced this issue Mar 13, 2020
buger pushed a commit that referenced this issue Mar 21, 2020
`Get()` and `EachKey()` will panic dealing with invalid parameters in some cases because of array out of bounds. This pr try to fix #177 and #178
@p4zuu p4zuu closed this as completed Apr 1, 2020
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