diff --git a/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDbDecoder.kt b/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDbDecoder.kt index e7b0eb14..e2bd3355 100644 --- a/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDbDecoder.kt +++ b/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDbDecoder.kt @@ -25,8 +25,7 @@ class AimeDbDecoder : ByteToMessageDecoder() { override fun decode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList) { if (input.readableBytes() < 16) return if (length == 0) length = getLength(input) - - if (input.readableBytes() < length) return + if (length < 0 || input.readableBytes() < length) return // Create a byte array to store the encrypted data val result = AimeDbEncryption.decrypt(input.readBytes(length)) @@ -46,7 +45,7 @@ class AimeDbDecoder : ByteToMessageDecoder() { * @param input the request * @return int the length of this request */ - private fun getLength(input: ByteBuf): Int { + private fun getLength(input: ByteBuf): Int = try { val currentPos = input.readerIndex() val result = AimeDbEncryption.decrypt(input) @@ -55,6 +54,10 @@ class AimeDbDecoder : ByteToMessageDecoder() { assert(header == 0x3e) { "AimeDB: Invalid header $header" } // Read the length from offset 6 - return result.getShortLE(currentPos + 6).toInt() + result.getShortLE(currentPos + 6).toInt() + } catch (e: Exception) { + logger.info("AimeDB: Invalid request received") + logger.debug("AimeDB: Invalid request received: ${input.toString(Charsets.UTF_8)}") + -1 } }