diff --git a/Spigot-Server-Patches/0405-Book-Size-Limits.patch b/Spigot-Server-Patches/0405-Book-Size-Limits.patch index 9487ef784b..386307fbb8 100644 --- a/Spigot-Server-Patches/0405-Book-Size-Limits.patch +++ b/Spigot-Server-Patches/0405-Book-Size-Limits.patch @@ -1,4 +1,4 @@ -From 903f06b5ea3616e0b4054b28c28d9d0b4b42a1aa Mon Sep 17 00:00:00 2001 +From 74ffd7f2292be3294d8d8c5f75525b6960266933 Mon Sep 17 00:00:00 2001 From: Aikar Date: Fri, 16 Nov 2018 23:08:50 -0500 Subject: [PATCH] Book Size Limits @@ -22,10 +22,19 @@ index fef899ae0..468aff713 100644 + } } diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java -index 7ae374085..bbdf729c3 100644 +index cb6d1deb8..8d06b23ea 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java -@@ -747,6 +747,38 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { +@@ -12,6 +12,8 @@ import java.util.Collections; + import java.util.Iterator; + import java.util.Set; + import javax.annotation.Nullable; ++ ++import org.apache.commons.lang3.StringEscapeUtils; + import org.apache.commons.lang3.StringUtils; + import org.apache.logging.log4j.LogManager; + import org.apache.logging.log4j.Logger; +@@ -747,6 +749,42 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { } public void a(PacketPlayInBEdit packetplayinbedit) { @@ -41,24 +50,28 @@ index 7ae374085..bbdf729c3 100644 + String testString = pageList.getString(i); + int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length; + byteTotal += byteLength; -+ if (byteTotal > byteAllowed) { -+ PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size()); -+ minecraftServer.postToMainThread(() -> this.disconnect("Book too large!")); -+ return; -+ } + int length = testString.length(); -+ int multibytes = byteLength == length ? byteLength : (int) Math.round((double) byteLength / (double) length); -+ for (int x = 1; x < multibytes; x++) { -+ multiplier *= multiplier; ++ int multibytes = 0; ++ if (byteLength != length) { ++ for (char c : testString.toCharArray()) { ++ if (c > 127) { ++ multibytes++; ++ } ++ } + } + byteAllowed += (maxBookPageSize * Math.min(1, Math.max(0.1D, (double) length / 255D))) * multiplier; -+ multiplier *= multiplier; + + if (multibytes > 1) { -+ // penalize MB some more -+ byteAllowed -= length; ++ // penalize MB ++ byteAllowed -= multibytes; + } + } ++ ++ if (byteTotal > byteAllowed) { ++ PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size()); ++ minecraftServer.postToMainThread(() -> this.disconnect("Book too large!")); ++ return; ++ } + } + // Paper end // CraftBukkit start diff --git a/Spigot-Server-Patches/0415-Fix-PlayerEditBookEvent.patch b/Spigot-Server-Patches/0415-Fix-PlayerEditBookEvent.patch index 72cfaa48e8..2d1b4515be 100644 --- a/Spigot-Server-Patches/0415-Fix-PlayerEditBookEvent.patch +++ b/Spigot-Server-Patches/0415-Fix-PlayerEditBookEvent.patch @@ -1,4 +1,4 @@ -From 84094387063f1158ef9192709e67e222cb39c5ed Mon Sep 17 00:00:00 2001 +From 73b51681652bfcf42e775aaff54db6c4d29b6ce9 Mon Sep 17 00:00:00 2001 From: Michael Himing Date: Sun, 16 Dec 2018 13:07:33 +1100 Subject: [PATCH] Fix PlayerEditBookEvent @@ -10,10 +10,10 @@ it impossible to properly cancel the event or modify the book meta cancelled writing diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java -index 74c570615..9741d3b23 100644 +index 8d06b23ea..a8a6e236e 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java -@@ -816,10 +816,13 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { +@@ -822,10 +822,13 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { this.player.setSlot(enumitemslot, CraftEventFactory.handleEditBookEvent(player, enumitemslot, itemstack1, itemstack2)); // CraftBukkit } else {