From d2c218e92b1902daa13d1d18e3121b1716716c2e Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Thu, 14 Oct 2021 21:44:48 +0800 Subject: [PATCH] fix: panic with invalid packet length. --- client/network.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/network.go b/client/network.go index 98a514b2..fa682377 100644 --- a/client/network.go +++ b/client/network.go @@ -191,6 +191,14 @@ func (c *QQClient) netLoop() { time.Sleep(time.Millisecond * 500) continue } + if l <= 0 || l > 1024*1024*10 { // max 10MB + c.Error("parse incoming packet error: invalid packet length %v", l) + errCount++ + if errCount > 2 { + go c.quickReconnect() + } + continue + } data, _ := c.TCP.ReadBytes(int(l) - 4) pkt, err := packets.ParseIncomingPacket(data, c.sigInfo.d2Key) if err != nil { @@ -203,7 +211,6 @@ func (c *QQClient) netLoop() { errCount++ if errCount > 2 { go c.quickReconnect() - continue } continue }