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

encoding/json: non-string map keys cause panic #8305

Closed
gopherbot opened this issue Jun 30, 2014 · 3 comments
Closed

encoding/json: non-string map keys cause panic #8305

gopherbot opened this issue Jun 30, 2014 · 3 comments
Milestone

Comments

@gopherbot
Copy link

by 2852914:

What does 'go version' print?

go version go1.3 linux/amd64

What steps reproduce the problem?

http://play.golang.org/p/lVP3r71dWS

1. Use a non-string key in a map to unmarshal into

What happened?

Invalid conversion inside the encoding/json decoder. Resulting in a panic.

What should have happened instead?

No panic should've happened.

Please provide any additional information below.

There are two bugs in play here.

The first panic occurs because the check for a map[string]T does not exit the decoding
step when it doesn't hold. This is visible at
http://golang.org/src/pkg/encoding/json/decode.go#L481 and the break on this line should
be a return.

The second panic, the one shown to the user occurs because the encoding/json package
uses panics as a unwinding mechanism, and always expects the argument given to panic to
be an error. In the case of an unexpected panic which does not send an error type, the
type assertion on http://golang.org/src/pkg/encoding/json/decode.go#L137 fails and is
propagated to the package user.

I'm of the opinion that the type-assertion panic should not be fixed, since it will hide
implementation bugs such as these.
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.4.

@gopherbot
Copy link
Author

Comment 2:

CL https://golang.org/cl/145680044 mentions this issue.

@griesemer
Copy link
Contributor

Comment 3:

This issue was closed by revision 7e8218a.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants