13
0
geforkt von Mirrors/Velocity

Improve reliability of varint decoder.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-09 14:37:43 -04:00
Ursprung f2e3b5c7ec
Commit 46aa8efb35

Datei anzeigen

@ -2,8 +2,10 @@ package com.velocitypowered.proxy.protocol.netty;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.CorruptedFrameException;
import java.util.List;
@ -15,12 +17,26 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
}
in.markReaderIndex();
int packetLength = ProtocolUtils.readVarInt(in);
if (in.readableBytes() < packetLength) {
in.resetReaderIndex();
return;
byte[] lenBuf = new byte[3];
for (int i = 0; i < lenBuf.length; i++) {
lenBuf[i] = in.readByte();
if (lenBuf[i] > 0) {
int packetLength = ProtocolUtils.readVarInt(Unpooled.wrappedBuffer(lenBuf));
if (packetLength == 0) {
return;
}
if (in.readableBytes() < packetLength) {
in.resetReaderIndex();
return;
}
out.add(in.readRetainedSlice(packetLength));
return;
}
}
out.add(in.readRetainedSlice(packetLength));
throw new CorruptedFrameException("VarInt too big");
}
}