a8m / a8m/djson

panic: runtime error: index out of range in (*Decoder).string

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
599
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Hello.

I found a index out of range bug in djson.

Please confirm.

Thanks.

reproduce code:
```
package djson

import (
"testing"
)

func TestFuzzCrashers(t *testing.T) {

var crashers = []string{
"{\"\":{\"\":{\"\":{\"\":{\"\":" +
"{\"\\",
}

for _, f := range crashers {
Decode([]byte(f))
}
}
```

Crash Log:
```
--- FAIL: TestFuzzCrashers (0.00s)
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range

goroutine 16 [running]:
panic(0x513c80, 0xc42000a120)
/usr/lib/go-1.7/src/runtime/panic.go:500 +0x1a1
testing.tRunner.func1(0xc4200689c0)
/usr/lib/go-1.7/src/testing/testing.go:579 +0x25d
panic(0x513c80, 0xc42000a120)
/usr/lib/go-1.7/src/runtime/panic.go:458 +0x243
github.com/a8m/djson.(*Decoder).string(0xc42003eec0, 0x0, 0xc420013380, 0x0, 0xc420013380)
/home/karas/go/src/github.com/a8m/djson/decode.go:224 +0x2f5
github.com/a8m/djson.(*Decoder).object(0xc420035eb0, 0xe, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:384 +0x11b
github.com/a8m/djson.(*Decoder).any(0xc420035eb0, 0x0, 0x0, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:176 +0x8ff
github.com/a8m/djson.(*Decoder).object(0xc420035eb0, 0x12, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:397 +0x1ac
github.com/a8m/djson.(*Decoder).any(0xc420035eb0, 0x0, 0x0, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:176 +0x8ff
github.com/a8m/djson.(*Decoder).object(0xc420035eb0, 0x16, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:397 +0x1ac
github.com/a8m/djson.(*Decoder).any(0xc420035eb0, 0x0, 0x0, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:176 +0x8ff
github.com/a8m/djson.(*Decoder).object(0xc420035eb0, 0x1a, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:397 +0x1ac
github.com/a8m/djson.(*Decoder).any(0xc420035eb0, 0x0, 0x0, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:176 +0x8ff
github.com/a8m/djson.(*Decoder).object(0xc420035eb0, 0x1e, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:397 +0x1ac
github.com/a8m/djson.(*Decoder).any(0xc420035eb0, 0x0, 0x0, 0x0, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:176 +0x8ff
github.com/a8m/djson.(*Decoder).object(0xc420035eb0, 0x5cf2a0, 0x100c00000000000, 0x0)
/home/karas/go/src/github.com/a8m/djson/decode.go:397 +0x1ac
github.com/a8m/djson.(*Decoder).any(0xc420035eb0, 0x100, 0xc420011960, 0x20, 0xc420011960)
/home/karas/go/src/github.com/a8m/djson/decode.go:176 +0x8ff
github.com/a8m/djson.Decode(0xc420011960, 0x17, 0x20, 0xc420011960, 0x17, 0x20, 0x6d5e5cf)
/home/karas/go/src/github.com/a8m/djson/interface.go:83 +0x76
github.com/a8m/djson.TestFuzzCrashers(0xc4200689c0)
/home/karas/go/src/github.com/a8m/djson/fuzzer_test.go:15 +0x84
testing.tRunner(0xc4200689c0, 0x545fc0)
/usr/lib/go-1.7/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
/usr/lib/go-1.7/src/testing/testing.go:646 +0x2ec
exit status 2
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The crash occurs in decode.go line 224 in the (*Decoder).string method. Start by examining the string parsing logic around that line to understand how index bounds are checked. The test case in fuzzer_test.go provides a minimal reproducing input. Run the test to confirm the panic, then trace through the nested object parsing to see where the index goes out of range.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.