diff --git a/rpc_util.go b/rpc_util.go index e006b7e6..9c8d8819 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -274,7 +274,10 @@ func (p *parser) recvMsg(maxReceiveMessageSize int) (pf payloadFormat, msg []byt if length == 0 { return pf, nil, nil } - if length > uint32(maxReceiveMessageSize) { + if int64(length) > int64(maxInt) { + return 0, nil, Errorf(codes.ResourceExhausted, "grpc: received message larger than max length allowed on current machine (%d vs. %d)", length, maxInt) + } + if int(length) > maxReceiveMessageSize { return 0, nil, Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", length, maxReceiveMessageSize) } // TODO(bradfitz,zhaoq): garbage. reuse buffer after proto decoding instead diff --git a/service_config.go b/service_config.go index 0631e7d2..cde64833 100644 --- a/service_config.go +++ b/service_config.go @@ -25,6 +25,8 @@ import ( "google.golang.org/grpc/grpclog" ) +const maxInt = int(^uint(0) >> 1) + // MethodConfig defines the configuration recommended by the service providers for a // particular method. // DEPRECATED: Users should not use this struct. Service config should be received @@ -97,8 +99,8 @@ type jsonMC struct { Name *[]jsonName WaitForReady *bool Timeout *string - MaxRequestMessageBytes *int - MaxResponseMessageBytes *int + MaxRequestMessageBytes *int64 + MaxResponseMessageBytes *int64 } // TODO(lyuxuan): delete this struct after cleaning up old service config implementation. @@ -135,8 +137,20 @@ func parseServiceConfig(js string) (ServiceConfig, error) { mc := MethodConfig{ WaitForReady: m.WaitForReady, Timeout: d, - MaxReqSize: m.MaxRequestMessageBytes, - MaxRespSize: m.MaxResponseMessageBytes, + } + if m.MaxRequestMessageBytes != nil { + if *m.MaxRequestMessageBytes > int64(maxInt) { + mc.MaxReqSize = newInt(maxInt) + } else { + mc.MaxReqSize = newInt(int(*m.MaxRequestMessageBytes)) + } + } + if m.MaxResponseMessageBytes != nil { + if *m.MaxResponseMessageBytes > int64(maxInt) { + mc.MaxRespSize = newInt(maxInt) + } else { + mc.MaxRespSize = newInt(int(*m.MaxResponseMessageBytes)) + } } for _, n := range *m.Name { if path, valid := n.generatePath(); valid {