Paper/patches/server/0282-Book-Size-Limits.patch
Jake Potrebic 3c0d6aaed9
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10085)
Upstream has released updates that appear 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:
0c7aedbc SPIGOT-7554, PR-954: Add DecoratedPotInventory

CraftBukkit Changes:
53ebb05e3 SPIGOT-7554, PR-1323: Add DecoratedPotInventory
33a2d8773 Ensure that PlayerMoveEvent is always fired where applicable
7df18510f SPIGOT-7555: Don't cast ItemFlags to byte
19aec59ea Use provided case for non-existent OfflinePlayers

Spigot Changes:
e7ce55a3 Remove obsolete PlayerMoveEvent improvements
3e5e22c0 Remove obsolete lowercasing of non existent OfflinePlayer names
2023-12-28 12:47:57 -08:00

58 lines
3.0 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/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 20b8fe97ee0b73e3b1a71b8366267d7c5de5da2e..f4c58330cc1f65231fa48a7dd4a199fbfc696f26 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1026,6 +1026,45 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
@Override
public void handleEditBook(ServerboundEditBookPacket packet) {
+ // Paper start
+ if (!this.cserver.isPrimaryThread()) {
+ List<String> pageList = packet.getPages();
+ long byteTotal = 0;
+ int maxBookPageSize = io.papermc.paper.configuration.GlobalConfiguration.get().itemValidation.bookSize.pageMax;
+ double multiplier = Math.max(0.3D, Math.min(1D, io.papermc.paper.configuration.GlobalConfiguration.get().itemValidation.bookSize.totalMultiplier));
+ long byteAllowed = maxBookPageSize;
+ for (String testString : pageList) {
+ int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
+ if (byteLength > 256 * 4) {
+ ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send a book with with a page too large!");
+ server.scheduleOnMain(() -> this.disconnect("Book too large!"));
+ return;
+ }
+ 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) {
+ ServerGamePacketListenerImpl.LOGGER.warn(this.player.getScoreboardName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
+ server.scheduleOnMain(() -> this.disconnect("Book too large!"));
+ return;
+ }
+ }
+ // Paper end
// CraftBukkit start
if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
this.disconnect("Book edited too quickly!");