From 01e57758bcc877fc8c632ed6d3dde00e092ce2d8 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Thu, 7 Feb 2019 13:32:00 -0800 Subject: [PATCH] grpc: limit reader with maxReceiveMessageSize (#2617) fixes #2616 --- rpc_util.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rpc_util.go b/rpc_util.go index af737734..2a595622 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -661,7 +661,9 @@ func recvAndDecompress(p *parser, s *transport.Stream, dc Decompressor, maxRecei if err != nil { return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) } - d, err = ioutil.ReadAll(dcReader) + // Read from LimitReader with limit max+1. So if the underlying + // reader is over limit, the result will be bigger than max. + d, err = ioutil.ReadAll(io.LimitReader(dcReader, int64(maxReceiveMessageSize)+1)) if err != nil { return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message %v", err) }