You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Failed type assertion generates a "special" zero value for json.SyntaxError here with its' msg being a nil pointer.
This causes a panic on trying to use its Error() method.
If not, ok will be false and t will be the zero value of type T, and no panic occurs.
It's also somewhat misleading that "zero value of type T" can mean two very different things; one generated by the process described in https://go.dev/ref/spec#The_zero_value which is the case here I believe, and one by json.SyntaxError{}. Apologies in advance if this goes beyond this bug report.
What did you see instead?
A segmentation fault due to null pointer dereference.
The text was updated successfully, but these errors were encountered:
havelock
changed the title
affected/package: encoding/json Error() methods not handling null pointers gracefully
encoding/json: Error() methods not handling null pointers gracefully
Dec 13, 2022
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/UzR0iDwh8eI
Failed type assertion generates a "special" zero value for
json.SyntaxError
here with its'msg
being a nil pointer.This causes a panic on trying to use its
Error()
method.What did you expect to see?
Error()
not causing null pointer dereference on an existing value that it's relatively simple to obtain; perhaps some simple "no error message" logics in https://cs.opensource.google/go/go/+/refs/tags/go1.19.4:src/encoding/json/scanner.go;l=52This can be the case for other errors too, at least in this package.
https://go.dev/tour/methods/15
It's also somewhat misleading that "zero value of type T" can mean two very different things; one generated by the process described in https://go.dev/ref/spec#The_zero_value which is the case here I believe, and one by
json.SyntaxError{}
. Apologies in advance if this goes beyond this bug report.What did you see instead?
A segmentation fault due to null pointer dereference.
The text was updated successfully, but these errors were encountered: