Check there are no trailing bytes in Rs2Decoder

Closes #137

Signed-off-by: Graham <gpe@openrs2.org>
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}" } logger.warn { "Skipping unimplemented packet: ${decoder.javaClass}" }
} }
if (payload.isReadable) {
throw DecoderException("Decoder didn't read entire payload: ${decoder.javaClass}")
}
state = State.READ_OPCODE state = State.READ_OPCODE
} }
} }

@ -59,6 +59,9 @@ public class CreateAccountCodec @Inject constructor(
val email = input.readString() val email = input.readString()
// padding
input.skipBytes(minOf(input.readableBytes(), XTEA_BLOCK_SIZE - 1))
return LoginRequest.CreateAccount( return LoginRequest.CreateAccount(
build, build,
gameNewsletters, 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) { private fun testDecode(buf: ByteArray, expected: Packet) {
val channel = EmbeddedChannel( val channel = EmbeddedChannel(
Rs2Decoder( Rs2Decoder(

Loading…
Cancel
Save