From 586bb91c0c29ecfa3d9e8c5620f853e44fb055a5 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Fri, 9 Apr 2021 18:11:07 +0800 Subject: [PATCH] Fix: grpc transport panic --- component/gun/gun.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/component/gun/gun.go b/component/gun/gun.go index 4ff5efe0..6136235d 100644 --- a/component/gun/gun.go +++ b/component/gun/gun.go @@ -83,7 +83,7 @@ func (g *Conn) Read(b []byte) (n int, err error) { g.br = nil } return - } else if g.remain != 0 { + } else if g.remain > 0 { size := g.remain if len(b) < size { size = len(b) @@ -113,7 +113,11 @@ func (g *Conn) Read(b []byte) (n int, err error) { if len(b) < bufferedSize { n, err = br.Read(b) 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 }