From 7e45c17b044592381910799d7db8e658339b1718 Mon Sep 17 00:00:00 2001 From: UserNugget <47762903+UserNugget@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:50:33 +0300 Subject: [PATCH] Limit maximum amount of known packs by vanilla defaults (#1303) --- .../proxy/protocol/packet/config/KnownPacksPacket.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/config/KnownPacksPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/config/KnownPacksPacket.java index db8bb1ec5..3a7d60cba 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/config/KnownPacksPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/config/KnownPacksPacket.java @@ -21,16 +21,25 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; public class KnownPacksPacket implements MinecraftPacket { + private static final int MAX_LENGTH_PACKS = Integer.getInteger("velocity.max-known-packs", 64); + private static final QuietDecoderException TOO_MANY_PACKS = + new QuietDecoderException("too many known packs"); + private KnownPack[] packs; @Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { final int packCount = ProtocolUtils.readVarInt(buf); + if (packCount > MAX_LENGTH_PACKS) { + throw TOO_MANY_PACKS; + } + final KnownPack[] packs = new KnownPack[packCount]; for (int i = 0; i < packCount; i++) {