Skip to content

Commit 9426974

Browse files
committed
don't try to decode packets before they have fully arrived
1 parent ab61a9e commit 9426974

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

common/src/main/java/me/mrnavastar/protoweaver/core/netty/ProtoPacketHandler.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@ public void channelInactive(ChannelHandlerContext ctx) {
5353

5454
@Override
5555
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> list) {
56-
if (byteBuf.readableBytes() == 0) return;
57-
Object packet = null;
56+
// Ensure the whole packet has arrived before trying to decode
57+
if (byteBuf.readableBytes() < 4) return;
58+
byteBuf.markReaderIndex();
59+
int packetLen = byteBuf.readInt();
60+
if (byteBuf.readableBytes() < packetLen) {
61+
byteBuf.resetReaderIndex();
62+
return;
63+
}
5864

65+
Object packet = null;
5966
try {
60-
byte[] bytes = new byte[byteBuf.readInt()];
67+
byte[] bytes = new byte[packetLen];
6168
byteBuf.readBytes(bytes);
6269
packet = connection.getProtocol().deserialize(bytes);
6370
handler.handlePacket(connection, packet);

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ waterfall_version=1.21-R0.1-SNAPSHOT
3030

3131
# Dependencies
3232
# https://github.com/apache/fury/releases
33-
fury_version=0.9.0
33+
fury_version=0.7.0
3434
r_version=1.0.8
3535
# should always match the netty version in (latest) minecraft release
3636
netty_version=4.1.97.Final

0 commit comments

Comments
 (0)