From f5bae877ea4dee4de611e94195f270de83a86291 Mon Sep 17 00:00:00 2001 From: Lukas Alt Date: Thu, 27 Apr 2023 20:50:14 +0200 Subject: [PATCH] Fixed large packet handling (#9147) Co-authored-by: Shane Freeder --- ...le-Large-Packets-disconnecting-client.patch | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/patches/server/Handle-Large-Packets-disconnecting-client.patch b/patches/server/Handle-Large-Packets-disconnecting-client.patch index 0bdf7443bd..acf81465b2 100644 --- a/patches/server/Handle-Large-Packets-disconnecting-client.patch +++ b/patches/server/Handle-Large-Packets-disconnecting-client.patch @@ -15,8 +15,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) { + // Paper start -+ if (throwable instanceof io.netty.handler.codec.EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException) { -+ if (((PacketEncoder.PacketTooLargeException) throwable.getCause()).getPacket().packetTooLarge(this)) { ++ if (throwable instanceof io.netty.handler.codec.EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException packetTooLargeException) { ++ if (packetTooLargeException.getPacket().packetTooLarge(this)) { ++ return; ++ } else if (packetTooLargeException.getPacket().isSkippable()) { ++ Connection.LOGGER.debug("Skipping packet due to errors", throwable.getCause()); + return; + } else { + throwable = throwable.getCause(); @@ -30,6 +33,15 @@ diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/j index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/network/PacketEncoder.java +++ b/src/main/java/net/minecraft/network/PacketEncoder.java +@@ -0,0 +0,0 @@ public class PacketEncoder extends MessageToByteEncoder> { + int j = friendlyByteBuf.writerIndex(); + packet.write(friendlyByteBuf); + int k = friendlyByteBuf.writerIndex() - j; +- if (k > 8388608) { ++ if (false && k > 8388608) { // Paper - disable + throw new IllegalArgumentException("Packet too big (is " + k + ", should be less than 8388608): " + packet); + } else { + int l = channelHandlerContext.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().getId(); @@ -0,0 +0,0 @@ public class PacketEncoder extends MessageToByteEncoder> { throw var10; } @@ -46,7 +58,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + + // Paper start -+ private static int MAX_PACKET_SIZE = 2097152; ++ private static int MAX_PACKET_SIZE = 8388608; + + public static class PacketTooLargeException extends RuntimeException { + private final Packet packet;