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/proto: do not panic when types do not match #4218

Merged
merged 2 commits into from
Feb 23, 2021

Conversation

menghanl
Copy link
Contributor

fixes #4213

The type mismatch can happen if

  1. user is using a non-proto generated code, so the message is not proto.Message
  2. the proto codec is picked (e.g. on receiving side, by content-type application/grpc+subtype)

return proto.Marshal(v.(proto.Message))
vv, ok := v.(proto.Message)
if !ok {
return nil, fmt.Errorf("failed to marshal, message is %T, want proto", v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: proto.Message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return proto.Unmarshal(data, v.(proto.Message))
vv, ok := v.(proto.Message)
if !ok {
return fmt.Errorf("failed to marshal, message is %T, want proto", v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"unmarshal", proto.Message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dfawley dfawley changed the title encoding proto: not panic when types do not match encoding/proto: do not panic when types do not match Feb 22, 2021
@menghanl menghanl merged commit dabedfb into grpc:master Feb 23, 2021
@menghanl menghanl deleted the not_panic_proto_codec branch February 23, 2021 17:47
menghanl added a commit to menghanl/grpc-go that referenced this pull request Feb 24, 2021
@menghanl menghanl modified the milestones: 1.37 Release, 1.36 Release Feb 24, 2021
menghanl added a commit to menghanl/grpc-go that referenced this pull request Feb 26, 2021
menghanl added a commit to menghanl/grpc-go that referenced this pull request Feb 26, 2021
menghanl added a commit that referenced this pull request Mar 11, 2021
Co-authored-by: Easwar Swaminathan <easwars@google.com>

This is a cherry pick of 
- encoding/proto: do not panic when types do not match (#4218)
- xds: add env var protection for client-side security (#4247)
menghanl added a commit that referenced this pull request Mar 11, 2021
Co-authored-by: Easwar Swaminathan <easwars@google.com>

This is a cherry pick of 
- encoding/proto: do not panic when types do not match (#4218)
- xds: add env var protection for client-side security (#4247)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flatbuffers codec] Content-subtype only set for go lang
3 participants