From b2d6e7423a1403298eec528ca3933723baa2ed15 Mon Sep 17 00:00:00 2001 From: sandtechnology <20417547+sandtechnology@users.noreply.github.com> Date: Sun, 11 Jul 2021 10:07:41 +0800 Subject: [PATCH] Fix #1405, before it is a compiler undefined behavior (#1408) --- .../commonMain/kotlin/network/components/PacketCodec.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt index ffd5bdea4..bc75115e6 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt @@ -209,11 +209,12 @@ internal class PacketCodecImpl : PacketCodec { (client as QQAndroidClient).bot.components[EcdhInitialPublicKeyUpdater].getECDHWithPublicKey() return when (encryptionMethod) { 4 -> { + val size = (this.remaining - 1).toInt() val data = TEA.decrypt( this.readBytes(), ecdhWithPublicKey.keyPair.maskedShareKey, - length = (this.remaining - 1).toInt() + length = size ) val peerShareKey = @@ -221,11 +222,12 @@ internal class PacketCodecImpl : PacketCodec { TEA.decrypt(data, peerShareKey) } 3 -> { + val size = (this.remaining - 1).toInt(); // session TEA.decrypt( this.readBytes(), client.wLoginSigInfo.wtSessionTicketKey, - length = (this.remaining - 1).toInt() + length = size ) } 0 -> { @@ -239,7 +241,8 @@ internal class PacketCodecImpl : PacketCodec { TEA.decrypt(byteArrayBuffer, client.randomKey, length = size) } } else { - TEA.decrypt(this.readBytes(), client.randomKey, length = (this.remaining - 1).toInt()) + val size = (this.remaining - 1).toInt() + TEA.decrypt(this.readBytes(), client.randomKey, length = size) } } else -> error("Illegal encryption method. expected 0 or 4, got $encryptionMethod")