-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proto, encoding/prototext, encoding/protojson: document that users should pass non-nil pointers to Unmarshal #937
Comments
This could be considered a DOS vulnerability for any grpc-gateway servers using timestamps in their public API. |
I'm sympathetic to this issue, but I'm hesitant to address it because of the performance overhead it introduces. The "fix" implies that the start of v := reflect.ValueOf(m)
if v.IsValid() && v.Kind() == reflect.Ptr && v.IsNil() {
return fmt.Errorf("Unmarshal(nil %T)", m)
} While it isn't particularly onerous, it is a non-trivial amount of overhead. If we're going to add this check to |
Ok, is it generally advised that we do not use nil pointers as arguments to Unmarshal, then? We can probably implement a fix for this in the gateway runtime. |
I can't think of any reasonable reason to pass a typed nil pointer to |
Fair enough, I will close this. What do you think about adding something to the documentation to discourage this use? |
We really should. Thanks for the suggestion. |
If we want to explicitly document that Unmarshal needs a non-nil pointer, then we should do so consistently across all unmarshal functions. |
Fixed with https://golang.org/cl/302329 |
Fixes golang#937 Change-Id: I40b2678eba0195ed01676167f8e01e2fedea293b Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302329 Trust: Joe Tsai <joetsai@digital-static.net> Reviewed-by: Damien Neil <dneil@google.com>
What version of protobuf and what language are you using?
golang/protobuf/jsonpb@1.3.2
.What did you do?
A bug report was raised against the grpc-gateway project whereby a certain type of invalid JSON input could sometimes cause a panic in the JSON unmarshalling code, as shown by this golang playground example:
https://play.golang.org/p/2VS9bEb7sgD
What did you expect to see?
I expected an error to be returned.
What did you see instead?
A panic with the following stack trace:
Anything else we should know about your project / environment?
Interestingly, the same panic does not happen when using a JSON string instead of a JSON number:
https://play.golang.org/p/kxOjuAuf4HM
It also doesn't happen when using a reference to a concrete value:
https://play.golang.org/p/kIAksR51kaz
I would argue that because case #1 above works fine, this is a bug in the unmarshalling code.
The text was updated successfully, but these errors were encountered: