From 2abd1d7ea03b83bd4e658c75d7460a6dcccaf3ff Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 26 Jul 2022 23:17:02 +0100 Subject: [PATCH] Fix CreateAccountCodec padding The padding must be between 1 and 8 bytes inclusive, not 0 and 7. Signed-off-by: Graham --- .../protocol/login/upstream/CreateAccountCodec.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateAccountCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateAccountCodec.kt index 8a6652fe..70762423 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateAccountCodec.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateAccountCodec.kt @@ -59,8 +59,12 @@ public class CreateAccountCodec @Inject constructor( val email = input.readString() - // padding - input.skipBytes(minOf(input.readableBytes(), XTEA_BLOCK_SIZE - 1)) + val padding = input.readableBytes() + require(padding in 1..XTEA_BLOCK_SIZE) { + "Padding ($padding bytes) must be between 1 and $XTEA_BLOCK_SIZE bytes" + } + + input.skipBytes(padding) return LoginRequest.CreateAccount( build, @@ -121,7 +125,8 @@ public class CreateAccountCodec @Inject constructor( output.writeString(input.email) - while ((output.writerIndex() - xteaIndex) % XTEA_BLOCK_SIZE != 0) { + val padding = XTEA_BLOCK_SIZE - (output.writerIndex() - xteaIndex) % XTEA_BLOCK_SIZE + for (i in 0 until padding) { output.writeByte(secureRandom.nextInt()) }