mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-19 09:05:43 +01:00
f17519338b
* Expose server build information * squash patches * final tweaks --------- Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: masmc05 <masmc05@gmail.com>
58 lines
3.0 KiB
Diff
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 e880b41e1824f986d04a0a32cc735d77f25cf987..3b3384fcbcb66a87dd50dece6bdac558491f66f0 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1040,6 +1040,45 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
@Override
|
|
public void handleEditBook(ServerboundEditBookPacket packet) {
|
|
+ // Paper start - Book size limits
|
|
+ if (!this.cserver.isPrimaryThread()) {
|
|
+ List<String> pageList = packet.pages();
|
|
+ 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 - Book size limits
|
|
// CraftBukkit start
|
|
if (this.lastBookTick + 20 > MinecraftServer.currentTick) {
|
|
this.disconnect("Book edited too quickly!");
|