Waterfall/BungeeCord-Patches/0047-Use-proper-max-length-for-serverbound-chat-packet.patch
_tomcraft 85c0a35f0b
Updated Upstream (BungeeCord) (#695)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

BungeeCord Changes:
6613aaea Add test fix for library classes being visible to non-dependent plugins
53ce6b93 #3200: Fix protocol for 21w40a
d8e29384 #2466: Use switch in "BungeeCord" plugin message handling
5cf869df #3198: Remove terminally deprecated SecurityManager
f26f7d88 Add optional 1.18 (21w40a) snapshot protocol support
2021-10-09 10:43:12 +01:00

51 lines
2.0 KiB
Diff

From a8361371f69b268c3b3b29d5460a92ed56d99eca Mon Sep 17 00:00:00 2001
From: kashike <kashike@vq.lc>
Date: Wed, 20 Mar 2019 21:39:12 -0700
Subject: [PATCH] Use proper max length for serverbound chat packet
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
index 8b2a2822..ab9519f9 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
@@ -56,6 +56,20 @@ public abstract class DefinedPacket
return s;
}
+ // Waterfall start
+ public static void writeString(String s, final int maxLength, ByteBuf buf)
+ {
+ if ( s.length() > maxLength )
+ {
+ throw new OverflowPacketException( String.format( "Cannot send string longer than %s (got %s characters)", maxLength, s.length() ) );
+ }
+
+ byte[] b = s.getBytes( Charsets.UTF_8 );
+ writeVarInt( b.length, buf );
+ buf.writeBytes( b );
+ }
+ // Waterfall end
+
public static void writeArray(byte[] b, ByteBuf buf)
{
if ( b.length > Short.MAX_VALUE )
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java
index 11b04c2a..6034fc18 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java
@@ -54,6 +54,11 @@ public class Chat extends DefinedPacket
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
+ // Waterfall start
+ if (direction == ProtocolConstants.Direction.TO_CLIENT) {
+ writeString(this.message, Short.MAX_VALUE * 8 + 8, buf);
+ } else
+ // Waterfall end
writeString( message, buf );
if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{
--
2.30.1 (Apple Git-130)