From 564b87de1d8efcd0534f5e9c41c66819e6746109 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 12 Jan 2019 00:25:11 -0500 Subject: [PATCH] Avoid ByteBuf#slice(). We can simply reset the reader index. --- .../proxy/protocol/netty/MinecraftVarintFrameDecoder.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java index 01dda3641..10ffcb40b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java @@ -17,7 +17,7 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { return; } - ByteBuf lenBuf = ctx.alloc().buffer(3); + ByteBuf lenBuf = ctx.alloc().buffer(3).writeZero(3); int origReaderIndex = in.readerIndex(); try { for (int i = 0; i < 3; i++) { @@ -27,9 +27,11 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { } byte read = in.readByte(); - lenBuf.writeByte(read); + lenBuf.setByte(i, read); if (read > 0) { - int packetLength = ProtocolUtils.readVarInt(lenBuf.slice()); + // Make sure reader index of length buffer is returned to the beginning + lenBuf.readerIndex(0); + int packetLength = ProtocolUtils.readVarInt(lenBuf); if (packetLength == 0) { return; }