mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
b742f7a892
Upstream merge (we must go deeper) SpigotMC/Spigot@1e7bc383c3
113 lines
4.7 KiB
Diff
113 lines
4.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Thinkofdeath <thinkofdeath@spigotmc.org>
|
|
Date: Wed, 2 Jul 2014 23:35:51 +0100
|
|
Subject: [PATCH] Better item validation
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
@@ -0,0 +0,0 @@ public class PacketDataSerializer extends ByteBuf {
|
|
NBTTagCompound nbttagcompound = null;
|
|
|
|
if (itemstack.getItem().usesDurability() || itemstack.getItem().s()) {
|
|
+ // Spigot start - filter
|
|
+ itemstack = itemstack.cloneItemStack();
|
|
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
|
|
+ // Spigot end
|
|
nbttagcompound = itemstack.tag;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
@@ -0,0 +0,0 @@ import com.google.common.base.Strings;
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.google.common.collect.ImmutableMap.Builder;
|
|
|
|
+// Spigot start
|
|
+import static org.spigotmc.ValidateUtils.*;
|
|
+// Spigot end
|
|
+
|
|
@DelegateDeserialization(SerializableMeta.class)
|
|
class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
static final ItemMetaKey BOOK_TITLE = new ItemMetaKey("title");
|
|
@@ -0,0 +0,0 @@ class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
super(tag);
|
|
|
|
if (tag.hasKey(BOOK_TITLE.NBT)) {
|
|
- this.title = tag.getString(BOOK_TITLE.NBT);
|
|
+ this.title = limit( tag.getString(BOOK_TITLE.NBT), 1024 ); // Spigot
|
|
}
|
|
|
|
if (tag.hasKey(BOOK_AUTHOR.NBT)) {
|
|
- this.author = tag.getString(BOOK_AUTHOR.NBT);
|
|
+ this.author = limit( tag.getString(BOOK_AUTHOR.NBT), 1024 ); // Spigot
|
|
}
|
|
|
|
if (tag.hasKey(BOOK_PAGES.NBT)) {
|
|
@@ -0,0 +0,0 @@ class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
String[] pageArray = new String[pages.size()];
|
|
|
|
for (int i = 0; i < pages.size(); i++) {
|
|
- String page = pages.getString(i);
|
|
+ String page = limit( pages.getString(i), 2048 ); // Spigot
|
|
pageArray[i] = page;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -0,0 +0,0 @@ import com.google.common.base.Strings;
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
+// Spigot start
|
|
+import static org.spigotmc.ValidateUtils.*;
|
|
+// Spigot end
|
|
+
|
|
/**
|
|
* Children must include the following:
|
|
*
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
NBTTagCompound display = tag.getCompound(DISPLAY.NBT);
|
|
|
|
if (display.hasKey(NAME.NBT)) {
|
|
- displayName = display.getString(NAME.NBT);
|
|
+ displayName = limit( display.getString(NAME.NBT), 1024 ); // Spigot
|
|
}
|
|
|
|
if (display.hasKey(LORE.NBT)) {
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
lore = new ArrayList<String>(list.size());
|
|
|
|
for (int index = 0; index < list.size(); index++) {
|
|
- String line = list.getString(index);
|
|
+ String line = limit( list.getString(index), 1024 ); // Spigot
|
|
lore.add(line);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/spigotmc/ValidateUtils.java b/src/main/java/org/spigotmc/ValidateUtils.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/spigotmc/ValidateUtils.java
|
|
@@ -0,0 +0,0 @@
|
|
+package org.spigotmc;
|
|
+
|
|
+public class ValidateUtils
|
|
+{
|
|
+
|
|
+ public static String limit(String str, int limit)
|
|
+ {
|
|
+ if ( str.length() > limit )
|
|
+ {
|
|
+ return str.substring( 0, limit );
|
|
+ }
|
|
+ return str;
|
|
+ }
|
|
+}
|
|
--
|