diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index baa5bc176..2804a978a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -67,21 +67,15 @@ public enum ProtocolUtils { */ public static int readVarIntSafely(ByteBuf buf) { int i = 0; - int j = 0; - while (true) { - if (!buf.isReadable()) { - return Integer.MIN_VALUE; - } + int maxRead = Math.min(5, buf.readableBytes()); + for (int j = 0; j < maxRead; j++) { int k = buf.readByte(); - i |= (k & 0x7F) << j++ * 7; - if (j > 5) { - return Integer.MIN_VALUE; - } + i |= (k & 0x7F) << j * 7; if ((k & 0x80) != 128) { - break; + return i; } } - return i; + return Integer.MIN_VALUE; } /** 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 18e35898d..3415c12da 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 @@ -42,8 +42,6 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { if (in.isReadable(minimumRead)) { out.add(in.retainedSlice(varintEnd + 1, reader.readVarint)); in.skipBytes(minimumRead); - } else { - return; } } } else if (reader.result == DecodeResult.TOO_BIG) {