fix bug of read to many bytes

This commit is contained in:
hebo 2019-09-26 08:59:42 +08:00
parent f60f43046d
commit f5b8337638
1 changed files with 14 additions and 16 deletions

View File

@ -100,7 +100,7 @@ func (ms *MysqlSession) resetBeginTime() {
}
func (ms *MysqlSession) readFromServer(bytes []byte) {
if ms.expectSendSize < 1 {
if ms.expectSendSize < 1 && len(bytes) > 4 {
ms.expectSendSize = extractMysqlPayloadSize(bytes[:4])
contents := bytes[4:]
if ms.prepareInfo != nil && contents[0] == 0 {
@ -160,7 +160,6 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
ms.beginSeqID = seqID
ms.endSeqID = seqID
if int64(ms.expectReceiveSize) < int64(len(contents)) {
log.Warnf("receive invalid mysql packet")
return
@ -204,7 +203,6 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
// ms.expectReceiveSize = ms.expectReceiveSize - int(contentSize)
}
func (ms *MysqlSession) GenerateQueryPiece() (qp model.QueryPiece) {
defer ms.clear()