Check there are no trailing bytes in Rs2Decoder

Closes #137

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 2 years ago
parent 0a99813932
commit e4b5f8b850
  1. 4
      protocol/src/main/kotlin/org/openrs2/protocol/Rs2Decoder.kt
  2. 3
      protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateAccountCodec.kt
  3. 10
      protocol/src/test/kotlin/org/openrs2/protocol/Rs2DecoderTest.kt

@ -59,6 +59,10 @@ public class Rs2Decoder(public var protocol: Protocol) : ByteToMessageDecoder()
logger.warn { "Skipping unimplemented packet: ${decoder.javaClass}" }
}
if (payload.isReadable) {
throw DecoderException("Decoder didn't read entire payload: ${decoder.javaClass}")
}
state = State.READ_OPCODE
}
}

@ -59,6 +59,9 @@ public class CreateAccountCodec @Inject constructor(
val email = input.readString()
// padding
input.skipBytes(minOf(input.readableBytes(), XTEA_BLOCK_SIZE - 1))
return LoginRequest.CreateAccount(
build,
gameNewsletters,

@ -69,6 +69,16 @@ class Rs2DecoderTest {
}
}
@Test
fun testTrailingBytes() {
val decoder = Rs2Decoder(Protocol(LengthMismatchPacketCodec))
val channel = EmbeddedChannel(decoder)
assertFailsWith<DecoderException> {
channel.writeInbound(wrappedBuffer(0, 0x11, 0x22, 0x33, 0x44, 0x55))
}
}
private fun testDecode(buf: ByteArray, expected: Packet) {
val channel = EmbeddedChannel(
Rs2Decoder(

Loading…
Cancel
Save