Skip to content

Panic (index out of range) inside the library when attempting to unmarshal large file. #194

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

Closed
marcopaganini opened this issue Nov 10, 2017 · 3 comments

Comments

@marcopaganini
Copy link

I'm attempting to Unmarshal a data buffer with the contents of a large file (Download), but I get an error inside the json-iterator code:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/json-iterator/go.growOne(0xc420094300, 0x5fb680, 0x5134c0, 0x5fb680, 0x535180)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect_slice.go:134 +0x17a
github.com/json-iterator/go.(*sliceDecoder).doDecode.func1(0xc420610000, 0x51342c)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect_slice.go:100 +0x68
github.com/json-iterator/go.(*Iterator).ReadArrayCB(0xc420610000, 0xc42004f738, 0x5134c0)
        /home/paganini/go/src/github.com/json-iterator/go/feature_iter_array.go:39 +0xc3
github.com/json-iterator/go.(*sliceDecoder).doDecode(0xc4200948d0, 0xc420094300, 0xc420610000)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect_slice.go:99 +0xfc
github.com/json-iterator/go.(*sliceDecoder).Decode(0xc4200948d0, 0xc420094300, 0xc420610000)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect_slice.go:82 +0x4c
github.com/json-iterator/go.(*structFieldDecoder).Decode(0xc420098800, 0xc420094300, 0xc420610000)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect_struct_decoder.go:930 +0x5c
github.com/json-iterator/go.(*twoFieldsStructDecoder).Decode(0xc420094ea0, 0xc420094300, 0xc420610000)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect_struct_decoder.go:524 +0x264
github.com/json-iterator/go.(*Iterator).ReadVal(0xc420610000, 0x50e480, 0xc420094300)
        /home/paganini/go/src/github.com/json-iterator/go/feature_reflect.go:236 +0xd1
github.com/json-iterator/go.(*frozenConfig).Unmarshal(0xc4200a8400, 0xc520266000, 0x9985053d, 0xfffffe00, 0x50e480, 0xc420094300, 0x0, 0x0)
        /home/paganini/go/src/github.com/json-iterator/go/feature_config.go:319 +0x1ab
main.main()
        /home/paganini/go/src/github.com/marcopaganini/op-desafios/desafio-05/marcopaganini/d05.go:100 +0x1fc

This particular file is parsed by the standard encoding/json library without any problems.

@taowen taowen closed this as completed in 9fddff0 Nov 11, 2017
@taowen
Copy link
Contributor

taowen commented Nov 11, 2017

from your test https://github.com/marcopaganini/op-desafios/blob/master/desafio-05/marcopaganini/d05.go

I find the Salario is of type int, but actual value is float in the json file.

@marcopaganini
Copy link
Author

This is not the problem. You looked at the "master" branch. The correct source is the "dev" branch:
https://github.com/marcopaganini/op-desafios/blob/dev/desafio-05/marcopaganini/d05.go

The problem still happens with Salario being a float64.

Incidentally, a colleague poked at this very same problem and got to feature_reflect_slice.go, lines 131/132:

srcPtr := (*[1 << 30]byte)(slice.Data)
dstPtr := (*[1 << 30]byte)(dst)

He changed the 30 above in the shift operation to 31 and things seem to pass. Do we have a design limitation in json-iterator?

@taowen
Copy link
Contributor

taowen commented Nov 11, 2017

the hard coded 30 has been changed in 9fddff0

zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
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

2 participants