From eb30451cfab174a58f1fa7ed39d773ee946ded31 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:01:27 -0500 Subject: [PATCH] [O] Aimedb: ignore invalid requests --- .../icu/samnyan/aqua/sega/aimedb/AimeDbDecoder.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 } }