aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSpottedleaf <[email protected]>2024-04-23 02:03:42 -0700
committerSpottedleaf <[email protected]>2024-04-23 02:03:54 -0700
commit37ae2392cfc2edc4b11a41fabaedda1d68f35958 (patch)
treebde3e455902c5814758b6eccf13a3808f2ee9d99
parentf4c7d373e4a1aff23539fe099745bf29a28559b9 (diff)
downloadPaper-37ae2392cfc2edc4b11a41fabaedda1d68f35958.tar.gz
Paper-37ae2392cfc2edc4b11a41fabaedda1d68f35958.zip
Adjust large packet handler to run when above protocol limit
Previously, PacketEncoder assumed that a packet value larger than the protocol limit would be compressed to become smaller than the protocol limit. However, not all packets will compress below the protocol limit. To try to better handle this, we will run the large packet handler when the packet size is above the protocol limit when the packet has a large packet fallback to avoid a case where the packet does not compress below protocol limit (at which point, it is too late to run the large packet handler).
-rw-r--r--patches/server/1060-fixup-Handle-Large-Packets-disconnecting-client.patch66
1 files changed, 66 insertions, 0 deletions
diff --git a/patches/server/1060-fixup-Handle-Large-Packets-disconnecting-client.patch b/patches/server/1060-fixup-Handle-Large-Packets-disconnecting-client.patch
new file mode 100644
index 0000000000..004b1e4677
--- /dev/null
+++ b/patches/server/1060-fixup-Handle-Large-Packets-disconnecting-client.patch
@@ -0,0 +1,66 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Spottedleaf <[email protected]>
+Date: Tue, 23 Apr 2024 02:01:59 -0700
+Subject: [PATCH] fixup! Handle Large Packets disconnecting client
+
+
+diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
+index 96d5448019d53ac3575e209c1c5c223a62a2638d..f396ca17e65138f5d128490b05bcd2f9c1d46ef5 100644
+--- a/src/main/java/net/minecraft/network/PacketEncoder.java
++++ b/src/main/java/net/minecraft/network/PacketEncoder.java
+@@ -63,7 +63,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
+ } finally {
+ // Paper start - Handle large packets disconnecting client
+ int packetLength = friendlyByteBuf.readableBytes();
+- if (packetLength > MAX_PACKET_SIZE) {
++ if (packetLength > MAX_PACKET_SIZE || (packetLength > MAX_FINAL_PACKET_SIZE && packet.hasLargePacketFallback())) {
+ throw new PacketTooLargeException(packet, this.codecKey, packetLength);
+ }
+ // Paper end - Handle large packets disconnecting client
+@@ -74,7 +74,10 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
+ }
+
+ // Paper start
+- private static int MAX_PACKET_SIZE = 8388608;
++ // packet size is encoded into 3-byte varint
++ private static final int MAX_FINAL_PACKET_SIZE = (1 << 21) - 1;
++ // Vanilla Max size for the encoder (before compression)
++ private static final int MAX_PACKET_SIZE = 8388608;
+
+ public static class PacketTooLargeException extends RuntimeException {
+ private final Packet<?> packet;
+diff --git a/src/main/java/net/minecraft/network/protocol/Packet.java b/src/main/java/net/minecraft/network/protocol/Packet.java
+index da11266a0a23f446196e6facf2c358cfcc18070f..9915e5996b9bf4b94653d0c2f612806db5c43485 100644
+--- a/src/main/java/net/minecraft/network/protocol/Packet.java
++++ b/src/main/java/net/minecraft/network/protocol/Packet.java
+@@ -35,6 +35,14 @@ public interface Packet<T extends PacketListener> {
+ default java.util.List<Packet<?>> getExtraPackets() {
+ return null;
+ }
++
++ default boolean hasLargePacketFallback() {
++ return false;
++ }
++
++ /**
++ * override {@link #hasLargePacketFallback()} to return true when overriding in subclasses
++ */
+ default boolean packetTooLarge(net.minecraft.network.Connection manager) {
+ return false;
+ }
+diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
+index 6765175c98d52e5cbc191e88e0d545a05606dfd4..3d52fd6de8b33e45450bb601697920bf94493fb9 100644
+--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
++++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
+@@ -32,6 +32,11 @@ public class ClientboundContainerSetContentPacket implements Packet<ClientGamePa
+ }
+
+ // Paper start
++ @Override
++ public boolean hasLargePacketFallback() {
++ return true;
++ }
++
+ @Override
+ public boolean packetTooLarge(net.minecraft.network.Connection manager) {
+ for (int i = 0 ; i < this.items.size() ; i++) {