From 642d3af7c2e2537c49af02090b2ff7f17424c5e9 Mon Sep 17 00:00:00 2001 From: kashike 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 0cef9430..d51a3142 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 e3a4d250..4749a671 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.31.1.windows.1