mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
ab347c4c96
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 42d5a714 SPIGOT-5899: Hoglins API similar to Piglins 2c1ee10e SPIGOT-5887: ClickType doesn't include off hand swaps 5ff7c7ce SPIGOT-5886: Missing BlockData CraftBukkit Changes:7560f5f5
SPIGOT-5905: Fix hex colours not being allowed in MOTDd47c47ee
SPIGOT-5889: Villager using composter should call EntityChangeBlockEvent2fe6b4a3
SPIGOT-5899: Hoglins API similar to Piglinse09dbeca
SPIGOT-5887: ClickType doesn't include off hand swaps23aac2a5
SPIGOT-5903: EntityDismountEvent cannot be triggered asynchronously92cbf656
SPIGOT-5884: Tab completions lost on reloadData / minecraft:reloadfb4e54ad
SPIGOT-5902: PlayerRespawnEvent places player at spawn before event is calledaa8f3d5a
SPIGOT-5901: Structures are generated in all worlds based on the setting for the main worlda0c35937
SPIGOT-5895: PlayerChangedWorldEvent#getFrom is incorrect89c0a5c3
SPIGOT-5886: Missing BlockData Spigot Changes: 0287a20d SPIGOT-5903: EntityDismountEvent cannot be triggered asynchronously
79 lines
3.8 KiB
Diff
79 lines
3.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 16 Nov 2018 23:08:50 -0500
|
|
Subject: [PATCH] Book Size Limits
|
|
|
|
Puts some limits on the size of books.
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
index 478856f190a8d0177dee39dab4692fc54f9c8ed4..01d48da8b2f89ad3a615ad10c044c5f0a08ee4ed 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
@@ -334,4 +334,11 @@ public class PaperConfig {
|
|
velocitySecretKey = secret.getBytes(StandardCharsets.UTF_8);
|
|
}
|
|
}
|
|
+
|
|
+ public static int maxBookPageSize = 2560;
|
|
+ public static double maxBookTotalSizeMultiplier = 0.98D;
|
|
+ private static void maxBookSize() {
|
|
+ maxBookPageSize = getInt("settings.book-size.page-max", maxBookPageSize);
|
|
+ maxBookTotalSizeMultiplier = getDouble("settings.book-size.total-multiplier", maxBookTotalSizeMultiplier);
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index a628f6b2aa792e53f223d40b2fd6a51826bc5c2a..148d5037db35437136242af07f6cb5aacee6177f 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -14,6 +14,7 @@ import java.util.Optional;
|
|
import java.util.Set;
|
|
import java.util.stream.Stream;
|
|
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;
|
|
@@ -814,6 +815,42 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
|
|
@Override
|
|
public void a(PacketPlayInBEdit packetplayinbedit) {
|
|
+ // Paper start
|
|
+ ItemStack testStack = packetplayinbedit.b();
|
|
+ if (!server.isPrimaryThread() && !testStack.isEmpty() && testStack.getTag() != null) {
|
|
+ NBTTagList pageList = testStack.getTag().getList("pages", 8);
|
|
+ long byteTotal = 0;
|
|
+ int maxBookPageSize = com.destroystokyo.paper.PaperConfig.maxBookPageSize;
|
|
+ double multiplier = Math.max(0.3D, Math.min(1D, com.destroystokyo.paper.PaperConfig.maxBookTotalSizeMultiplier));
|
|
+ long byteAllowed = maxBookPageSize;
|
|
+ for (int i = 0; i < pageList.size(); ++i) {
|
|
+ String testString = pageList.getString(i);
|
|
+ int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
|
+ byteTotal += byteLength;
|
|
+ int length = testString.length();
|
|
+ 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;
|
|
+
|
|
+ if (multibytes > 1) {
|
|
+ // 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.scheduleOnMain(() -> this.disconnect("Book too large!"));
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinbedit, this, this.player.getWorldServer());
|
|
// CraftBukkit start
|
|
if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
|