From 245e2d10613897998ef641dcd6d69a8f5fb6c3a1 Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Thu, 28 Feb 2019 18:07:14 +0000 Subject: [PATCH] Apply sign limits to signs text content --- .../Fix-sign-edit-memory-leak.patch | 4 +-- ...Strip-extra-Sign-data-to-from-client.patch | 28 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Spigot-Server-Patches/Fix-sign-edit-memory-leak.patch b/Spigot-Server-Patches/Fix-sign-edit-memory-leak.patch index 82113e2be0..7fc81c4a7c 100644 --- a/Spigot-Server-Patches/Fix-sign-edit-memory-leak.patch +++ b/Spigot-Server-Patches/Fix-sign-edit-memory-leak.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Fix sign edit memory leak when a player edits a sign, a reference to their Entity is never cleand up. diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java -index 9b857a8d1d..53ef6bf175 100644 +index 9b857a8d1..53ef6bf17 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { @@ -19,7 +19,7 @@ index 9b857a8d1d..53ef6bf175 100644 this.sendPacket(tileentity.getUpdatePacket()); // CraftBukkit return; diff --git a/src/main/java/net/minecraft/server/TileEntitySign.java b/src/main/java/net/minecraft/server/TileEntitySign.java -index 9dbdabeb0c..0a5971d0ec 100644 +index 05fb2eea5..ca80391d7 100644 --- a/src/main/java/net/minecraft/server/TileEntitySign.java +++ b/src/main/java/net/minecraft/server/TileEntitySign.java @@ -0,0 +0,0 @@ public class TileEntitySign extends TileEntity implements ICommandListener { diff --git a/Spigot-Server-Patches/Strip-extra-Sign-data-to-from-client.patch b/Spigot-Server-Patches/Strip-extra-Sign-data-to-from-client.patch index fa37e802f9..6a40caec35 100644 --- a/Spigot-Server-Patches/Strip-extra-Sign-data-to-from-client.patch +++ b/Spigot-Server-Patches/Strip-extra-Sign-data-to-from-client.patch @@ -20,7 +20,7 @@ it only impacts data sent to and from the client. Set -DPaper.maxSignLength=XX to change limit or -1 to disable diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java -index 04344a3711..9b857a8d1d 100644 +index 04344a371..9b857a8d1 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { @@ -36,9 +36,17 @@ index 04344a3711..9b857a8d1d 100644 } SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.server.getPlayer(this.player), lines); diff --git a/src/main/java/net/minecraft/server/TileEntitySign.java b/src/main/java/net/minecraft/server/TileEntitySign.java -index c2bcbbbab9..9dbdabeb0c 100644 +index c2bcbbbab..05fb2eea5 100644 --- a/src/main/java/net/minecraft/server/TileEntitySign.java +++ b/src/main/java/net/minecraft/server/TileEntitySign.java +@@ -0,0 +0,0 @@ + package net.minecraft.server; + + import com.mojang.brigadier.exceptions.CommandSyntaxException; ++ + import javax.annotation.Nullable; + + public class TileEntitySign extends TileEntity implements ICommandListener { @@ -0,0 +0,0 @@ public class TileEntitySign extends TileEntity implements ICommandListener { // Paper start - Strip invalid unicode from signs on load private static final boolean keepInvalidUnicode = Boolean.getBoolean("Paper.keepInvalidUnicode"); // Allow people to keep their bad unicode if they really want it @@ -59,13 +67,19 @@ index c2bcbbbab9..9dbdabeb0c 100644 super.save(nbttagcompound); for (int i = 0; i < 4; ++i) { - String s = IChatBaseComponent.ChatSerializer.a(this.lines[i]); +- String s = IChatBaseComponent.ChatSerializer.a(this.lines[i]); ++ // Paper start ++ String component = org.bukkit.craftbukkit.util.CraftChatMessage.fromComponent(lines[i]); ++ ++ if (filterLines && MAX_SIGN_LINE_LENGTH > 0 && component.length() > MAX_SIGN_LINE_LENGTH) { ++ component = component.substring(0, MAX_SIGN_LINE_LENGTH); ++ } ++ ++ String s = org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(org.bukkit.craftbukkit.util.CraftChatMessage.fromString(component)[0]); ++ // Paper end -- nbttagcompound.setString("Text" + (i + 1), s); -+ nbttagcompound.setString("Text" + (i + 1), filterLines && MAX_SIGN_LINE_LENGTH > 0 && s.length() > MAX_SIGN_LINE_LENGTH ? s.substring(0, MAX_SIGN_LINE_LENGTH): s); // Paper + nbttagcompound.setString("Text" + (i + 1), s); } - - // CraftBukkit start @@ -0,0 +0,0 @@ public class TileEntitySign extends TileEntity implements ICommandListener { }