[O] Aimedb: ignore invalid requests

pull/17/head
Azalea 2024-03-03 18:01:27 -05:00
parent a48f2b1f17
commit eb30451cfa
1 changed files with 7 additions and 4 deletions

View File

@ -25,8 +25,7 @@ class AimeDbDecoder : ByteToMessageDecoder() {
override fun decode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList<Any>) {
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
}
}