mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
fix crash caused by malformed packet.
This commit is contained in:
parent
b349c8ff66
commit
670b4084ce
@ -113,12 +113,14 @@ func ParseIncomingPacket(payload, d2key []byte) (*IncomingPacket, error) {
|
|||||||
if flag1 != 0x0A && flag1 != 0x0B {
|
if flag1 != 0x0A && flag1 != 0x0B {
|
||||||
return nil, ErrDecryptFailed
|
return nil, ErrDecryptFailed
|
||||||
}
|
}
|
||||||
return parseSsoFrame(decrypted, flag2), nil
|
return parseSsoFrame(decrypted, flag2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSsoFrame(payload []byte, flag2 byte) *IncomingPacket {
|
func parseSsoFrame(payload []byte, flag2 byte) (*IncomingPacket, error) {
|
||||||
reader := binary.NewReader(payload)
|
reader := binary.NewReader(payload)
|
||||||
reader.ReadInt32() // packet len
|
if reader.ReadInt32()-4 > int32(reader.Len()) {
|
||||||
|
return nil, errors.New("dropped")
|
||||||
|
}
|
||||||
seqId := reader.ReadInt32()
|
seqId := reader.ReadInt32()
|
||||||
reader.ReadInt32() // return code
|
reader.ReadInt32() // return code
|
||||||
reader.ReadBytes(int(reader.ReadInt32()) - 4) // extra data
|
reader.ReadBytes(int(reader.ReadInt32()) - 4) // extra data
|
||||||
@ -131,7 +133,7 @@ func parseSsoFrame(payload []byte, flag2 byte) *IncomingPacket {
|
|||||||
CommandName: commandName,
|
CommandName: commandName,
|
||||||
SessionId: sessionId,
|
SessionId: sessionId,
|
||||||
Payload: []byte{},
|
Payload: []byte{},
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
compressedFlag := reader.ReadInt32()
|
compressedFlag := reader.ReadInt32()
|
||||||
packet := func() []byte {
|
packet := func() []byte {
|
||||||
@ -158,7 +160,7 @@ func parseSsoFrame(payload []byte, flag2 byte) *IncomingPacket {
|
|||||||
CommandName: commandName,
|
CommandName: commandName,
|
||||||
SessionId: sessionId,
|
SessionId: sessionId,
|
||||||
Payload: packet,
|
Payload: packet,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pkt *IncomingPacket) DecryptPayload(random []byte) ([]byte, error) {
|
func (pkt *IncomingPacket) DecryptPayload(random []byte) ([]byte, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user