Fix: grpc transport panic

This commit is contained in:
Dreamacro 2021-04-09 18:11:07 +08:00
parent baf03b81e3
commit 586bb91c0c

View file

@ -83,7 +83,7 @@ func (g *Conn) Read(b []byte) (n int, err error) {
g.br = nil g.br = nil
} }
return return
} else if g.remain != 0 { } else if g.remain > 0 {
size := g.remain size := g.remain
if len(b) < size { if len(b) < size {
size = len(b) size = len(b)
@ -113,7 +113,11 @@ func (g *Conn) Read(b []byte) (n int, err error) {
if len(b) < bufferedSize { if len(b) < bufferedSize {
n, err = br.Read(b) n, err = br.Read(b)
g.br = br g.br = br
g.remain = int(protobufPayloadLen) - n - g.br.Buffered() remain := int(protobufPayloadLen) - n - g.br.Buffered()
if remain < 0 {
return 0, ErrInvalidLength
}
g.remain = remain
return return
} }