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

Panic when decoding json string #278

Closed
uunnii opened this issue Aug 17, 2021 · 0 comments · Fixed by #280
Closed

Panic when decoding json string #278

uunnii opened this issue Aug 17, 2021 · 0 comments · Fixed by #280
Labels
bug Something isn't working

Comments

@uunnii
Copy link

uunnii commented Aug 17, 2021

Hi!
When I was trying to decode a json string into an interface, I got a panic.
Seems it happened when unescaping Unicode characters.
Here is an example:

package main

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

func main() {
	a := `{"嗷嗷":["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\u55f7"]}`
	var o interface{}
	json.NewDecoder(bytes.NewBufferString(a)).Decode(&o)
}

Output:

panic: runtime error: slice bounds out of range [:504] with capacity 503

goroutine 1 [running]:
github.com/goccy/go-json/internal/decoder.decodeUnicodeRune(0xc00005a180, 0x0, 0x5c2900, 0x4ef360, 0x4e85a0, 0x7ff62a568858, 0xe000e000e000e)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/string.go:107 +0x31d
github.com/goccy/go-json/internal/decoder.decodeUnicode(0xc00005a180, 0x0, 0xc000010310, 0x50a121, 0x7ff65123f9f0)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/string.go:127 +0x4d
github.com/goccy/go-json/internal/decoder.decodeEscapeString(0xc00005a180, 0x0, 0x8, 0x18, 0x7ff651234108)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/string.go:161 +0x405
github.com/goccy/go-json/internal/decoder.(*interfaceDecoder).decodeStreamEmptyInterface(0xc000064050, 0xc00005a180, 0x2, 0xc0000580a0, 0x0, 0x0)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/interface.go:238 +0x21e
github.com/goccy/go-json/internal/decoder.(*interfaceDecoder).DecodeStream(0xc000064050, 0xc00005a180, 0x2, 0xc0000580a0, 0x18, 0x4e7140)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/interface.go:318 +0x1bc
github.com/goccy/go-json/internal/decoder.(*sliceDecoder).DecodeStream(0xc0001260e0, 0xc00005a180, 0x2, 0xc00000c078, 0xc000124002, 0xc00006cb68)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/slice.go:156 +0x556
github.com/goccy/go-json/internal/decoder.(*interfaceDecoder).decodeStreamEmptyInterface(0xc000064050, 0xc00005a180, 0x1, 0xc000010300, 0x0, 0x0)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/interface.go:225 +0x5e5
github.com/goccy/go-json/internal/decoder.(*interfaceDecoder).DecodeStream(0xc000064050, 0xc00005a180, 0x1, 0xc000010300, 0x0, 0x0)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/interface.go:318 +0x1bc
github.com/goccy/go-json/internal/decoder.(*mapDecoder).DecodeStream(0xc00005a240, 0xc00005a180, 0x1, 0xc000049d90, 0xc00006cd80, 0xc00006cd70)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/map.go:94 +0x31e
github.com/goccy/go-json/internal/decoder.(*interfaceDecoder).decodeStreamEmptyInterface(0xc0000640a0, 0xc00005a180, 0x0, 0xc000010290, 0x0, 0x0)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/interface.go:217 +0x6e5
github.com/goccy/go-json/internal/decoder.(*interfaceDecoder).DecodeStream(0xc0000640a0, 0xc00005a180, 0x0, 0xc000010290, 0x0, 0xc00006cee8)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/internal/decoder/interface.go:318 +0x1bc
github.com/goccy/go-json.(*Decoder).DecodeWithOption(0xc00006cf70, 0x4e4600, 0xc000010290, 0x0, 0x0, 0x0, 0x0, 0xc000038778)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/decode.go:202 +0x131
github.com/goccy/go-json.(*Decoder).Decode(...)
	/home/abc/go/pkg/mod/github.com/goccy/go-json@v0.7.6/decode.go:168
main.main()
	/home/abc/go/src/test/main.go:11 +0x1ce
@goccy goccy added the bug Something isn't working label Aug 18, 2021
orisano added a commit to orisano/go-json that referenced this issue Aug 24, 2021
orisano added a commit to orisano/go-json that referenced this issue Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants