geforkt von Mirrors/Velocity
Improve reliability of varint decoder.
Dieser Commit ist enthalten in:
Ursprung
f2e3b5c7ec
Commit
46aa8efb35
@ -2,8 +2,10 @@ package com.velocitypowered.proxy.protocol.netty;
|
|||||||
|
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -15,12 +17,26 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
in.markReaderIndex();
|
in.markReaderIndex();
|
||||||
int packetLength = ProtocolUtils.readVarInt(in);
|
|
||||||
|
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) {
|
if (in.readableBytes() < packetLength) {
|
||||||
in.resetReaderIndex();
|
in.resetReaderIndex();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.add(in.readRetainedSlice(packetLength));
|
out.add(in.readRetainedSlice(packetLength));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new CorruptedFrameException("VarInt too big");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren