2626import com .velocitypowered .api .proxy .messages .LegacyChannelIdentifier ;
2727import com .velocitypowered .api .proxy .messages .MinecraftChannelIdentifier ;
2828import com .velocitypowered .api .util .ProxyVersion ;
29+ import com .velocitypowered .proxy .connection .client .ConnectedPlayer ;
2930import com .velocitypowered .proxy .protocol .ProtocolUtils ;
3031import com .velocitypowered .proxy .protocol .netty .MinecraftDecoder ;
3132import com .velocitypowered .proxy .protocol .packet .PluginMessagePacket ;
@@ -96,10 +97,12 @@ public static boolean isUnregister(PluginMessagePacket message) {
9697 /**
9798 * Fetches all the channels in a register or unregister plugin message.
9899 *
100+ * @param existingChannels the number of channels already registered
99101 * @param message the message to get the channels from
100102 * @return the channels, as an immutable list
101103 */
102- public static List <ChannelIdentifier > getChannels (PluginMessagePacket message ,
104+ public static List <ChannelIdentifier > getChannels (int existingChannels ,
105+ PluginMessagePacket message ,
103106 ProtocolVersion protocolVersion ) {
104107 checkNotNull (message , "message" );
105108 checkArgument (isRegister (message ) || isUnregister (message ), "Unknown channel type %s" ,
@@ -110,7 +113,10 @@ public static List<ChannelIdentifier> getChannels(PluginMessagePacket message,
110113 return ImmutableList .of ();
111114 }
112115 String payload = message .content ().toString (StandardCharsets .UTF_8 );
116+ checkArgument (payload .length () <= Short .MAX_VALUE , "payload too long: %s" , payload .length ());
113117 String [] channels = payload .split ("\0 " );
118+ checkArgument (existingChannels + channels .length <= ConnectedPlayer .MAX_CLIENTSIDE_PLUGIN_CHANNELS ,
119+ "too many channels: %s + %s > %s" , existingChannels , channels .length , ConnectedPlayer .MAX_CLIENTSIDE_PLUGIN_CHANNELS );
114120 ImmutableList .Builder <ChannelIdentifier > channelIdentifiers = ImmutableList .builderWithExpectedSize (channels .length );
115121 try {
116122 for (String channel : channels ) {
0 commit comments