Remove outbound string length limits on signs, improve codepoint logic

now 80 chars counts multi sized code points the same so 80 chinese
characters would be allowed too.

Removed outbound limit as it doesn't solve the chunk oversize problem.

proper fix for chunk sending in another patch next.
This commit is contained in:
Aikar 2019-03-02 15:28:04 -05:00
parent 40f5a94b8f
commit 58398da145
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
3 changed files with 61 additions and 101 deletions

View file

@ -1,4 +1,4 @@
From 09a0ec26b1ed7bea71eb912b3dfc10c051cb2ae6 Mon Sep 17 00:00:00 2001
From da540325bd88cf730edad5ce1eb6d264f6eb543d Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 28 Feb 2019 00:15:28 -0500
Subject: [PATCH] Fix sign edit memory leak
@ -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 9b857a8d1..53ef6bf17 100644
index 04344a3711..5c58b85388 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2527,7 +2527,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
@ -19,18 +19,18 @@ index 9b857a8d1..53ef6bf17 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 05fb2eea5..ca80391d7 100644
index c2bcbbbab9..fdb771317a 100644
--- a/src/main/java/net/minecraft/server/TileEntitySign.java
+++ b/src/main/java/net/minecraft/server/TileEntitySign.java
@@ -16,6 +16,7 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
@@ -14,6 +14,7 @@ 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
private boolean privateUnicodeRemoved = false;
public static final int MAX_SIGN_LINE_LENGTH = Integer.getInteger("Paper.maxSignLength", 80);
+ public java.util.UUID signEditor;
// Paper end
public TileEntitySign() {
@@ -145,7 +146,10 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
@@ -130,7 +131,10 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
}
public void a(EntityHuman entityhuman) {
@ -43,5 +43,5 @@ index 05fb2eea5..ca80391d7 100644
public EntityHuman e() {
--
2.21.0
2.20.1

View file

@ -1,94 +0,0 @@
From b730a9659f67fda08d8de3a9eb395bef9dfdfe72 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 27 Feb 2019 22:18:40 -0500
Subject: [PATCH] Strip extra Sign data to/from client
modified clients can send abnormally large data from the client
to the server and it would get stored on the sign as sent.
the client can barely render around 16 characters as-is, but formatting
codes can get it to be more than 16 actual length.
Set a limit of 80 which should give an average of 16 characters 2
sets of legacy formatting codes which should be plenty for all uses.
This does not strip any existing data from the NBT as plugins
may use this for storing data out of the rendered area.
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 04344a371..9b857a8d1 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2543,6 +2543,11 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
String[] lines = new String[4];
for (int i = 0; i < astring.length; ++i) {
+ // Paper start - cap line length - modified clients can send longer data than normal
+ if (astring[i].length() > TileEntitySign.MAX_SIGN_LINE_LENGTH && TileEntitySign.MAX_SIGN_LINE_LENGTH > 0) {
+ astring[i] = astring[i].substring(0, TileEntitySign.MAX_SIGN_LINE_LENGTH);
+ }
+ // Paper end
lines[i] = SharedConstants.a(astring[i]); //Paper - Replaced with anvil color stripping method to stop exploits that allow colored signs to be created.
}
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 c2bcbbbab..05fb2eea5 100644
--- a/src/main/java/net/minecraft/server/TileEntitySign.java
+++ b/src/main/java/net/minecraft/server/TileEntitySign.java
@@ -1,6 +1,7 @@
package net.minecraft.server;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
+
import javax.annotation.Nullable;
public class TileEntitySign extends TileEntity implements ICommandListener {
@@ -14,17 +15,31 @@ 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
private boolean privateUnicodeRemoved = false;
+ public static final int MAX_SIGN_LINE_LENGTH = Integer.getInteger("Paper.maxSignLength", 80);
// Paper end
public TileEntitySign() {
super(TileEntityTypes.SIGN);
}
+ // Paper start
public NBTTagCompound save(NBTTagCompound nbttagcompound) {
+ return save(nbttagcompound, false);
+ }
+ public NBTTagCompound save(NBTTagCompound nbttagcompound, boolean filterLines) {
+ // Paper end
super.save(nbttagcompound);
for (int i = 0; i < 4; ++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);
}
@@ -118,7 +133,7 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
}
public NBTTagCompound aa_() {
- return this.save(new NBTTagCompound());
+ return this.save(new NBTTagCompound(), true); // Paper - filter lines
}
public boolean isFilteredNBT() {
--
2.21.0

View file

@ -0,0 +1,54 @@
From 7eba93a4292ea7e612ae168aa7ba7f6a9704ba9a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 27 Feb 2019 22:18:40 -0500
Subject: [PATCH] Limit Client Sign length more
modified clients can send more data from the client
to the server and it would get stored on the sign as sent.
Mojang has a limit of 384 which is much higher than reasonable.
the client can barely render around 16 characters as-is, but formatting
codes can get it to be more than 16 actual length.
Set a limit of 80 which should give an average of 16 characters 2
sets of legacy formatting codes which should be plenty for all uses.
This does not strip any existing data from the NBT as plugins
may use this for storing data out of the rendered area.
it only impacts data sent 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 5c58b85388..dc8c20efb4 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -104,6 +104,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
private int E;
private int receivedMovePackets;
private int processedMovePackets;
+ private static final int MAX_SIGN_LINE_LENGTH = Integer.getInteger("Paper.maxSignLength", 80);
private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
@@ -2543,6 +2544,15 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
String[] lines = new String[4];
for (int i = 0; i < astring.length; ++i) {
+ // Paper start - cap line length - modified clients can send longer data than normal
+ if (MAX_SIGN_LINE_LENGTH > 0 && astring[i].length() > MAX_SIGN_LINE_LENGTH) {
+ // This handles multibyte characters as 1
+ int offset = astring[i].codePoints().limit(MAX_SIGN_LINE_LENGTH).map(Character::charCount).sum();
+ if (offset > astring.length) {
+ astring[i] = astring[i].substring(0, offset);
+ }
+ }
+ // Paper end
lines[i] = SharedConstants.a(astring[i]); //Paper - Replaced with anvil color stripping method to stop exploits that allow colored signs to be created.
}
SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.server.getPlayer(this.player), lines);
--
2.20.1