blob: 004b1e46773c684d2c909ef1e23bceaa29fbf7ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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++) {
|