From 940f395e3e2b4df1f16d3457c9930f1c87bf1e18 Mon Sep 17 00:00:00 2001 From: Wouter Gritter Date: Tue, 1 Sep 2026 13:19:46 +0200 Subject: [PATCH] Use correct minimum ClientSettings packet length for older protocol versions For correctness's sake: in practice this bug never got triggered because `locale` is almost always a string of length 5+ ("en_us"). --- .../protocol/packet/ClientSettingsPacket.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java index b8b60a9f..7e6600cc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ClientSettingsPacket.java @@ -213,7 +213,34 @@ public class ClientSettingsPacket implements MinecraftPacket { @Override public int decodeExpectedMinLength(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { - return 1 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; + int minLength = 1 // locale + + 1 // viewDistance + + 1 // chatVisibility + + 1; // chatColors + + if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_7_6)) { + minLength += 1; // difficulty + } + + minLength += 1; // skinParts + + if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9)) { + minLength += 1; // mainHand + + if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) { + minLength += 1; // textFilteringEnabled + + if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) { + minLength += 1; // clientListingAllowed + + if (version.noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) { + minLength += 1; // particleStatus + } + } + } + } + + return minLength; } @Override