2015-03-08 11:04:41 +00:00
|
|
|
From 42df9e8c236f49c9ce63b62876e8f5dbb471d4e3 Mon Sep 17 00:00:00 2001
|
2014-07-21 20:46:54 +00:00
|
|
|
From: Thinkofdeath <thinkofdeath@spigotmc.org>
|
|
|
|
Date: Wed, 2 Jul 2014 23:35:51 +0100
|
|
|
|
Subject: [PATCH] Better item validation
|
|
|
|
|
|
|
|
|
2014-08-25 21:30:52 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/DataWatcher.java b/src/main/java/net/minecraft/server/DataWatcher.java
|
2015-02-28 11:36:22 +00:00
|
|
|
index aa46c28..dec091e 100644
|
2014-08-25 21:30:52 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/DataWatcher.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/DataWatcher.java
|
2015-02-28 11:36:22 +00:00
|
|
|
@@ -155,6 +155,17 @@ public class DataWatcher {
|
2014-11-28 01:17:45 +00:00
|
|
|
arraylist = Lists.newArrayList();
|
2014-08-25 21:30:52 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 11:36:22 +00:00
|
|
|
+ // Spigot start - copy ItemStacks to prevent ConcurrentModificationExceptions
|
|
|
|
+ if ( datawatcher_watchableobject.b() instanceof ItemStack )
|
2014-08-25 21:30:52 +00:00
|
|
|
+ {
|
2015-02-28 11:36:22 +00:00
|
|
|
+ datawatcher_watchableobject = new WatchableObject(
|
|
|
|
+ datawatcher_watchableobject.c(),
|
|
|
|
+ datawatcher_watchableobject.a(),
|
|
|
|
+ ( (ItemStack) datawatcher_watchableobject.b() ).cloneItemStack()
|
2014-08-25 21:30:52 +00:00
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+
|
2015-02-28 11:36:22 +00:00
|
|
|
arraylist.add(datawatcher_watchableobject);
|
2014-08-25 21:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-28 11:36:22 +00:00
|
|
|
@@ -186,6 +197,21 @@ public class DataWatcher {
|
2014-08-25 21:30:52 +00:00
|
|
|
this.f.readLock().lock();
|
|
|
|
|
|
|
|
arraylist.addAll(this.dataValues.valueCollection()); // Spigot
|
|
|
|
+ // Spigot start - copy ItemStacks to prevent ConcurrentModificationExceptions
|
|
|
|
+ for ( int i = 0; i < arraylist.size(); i++ )
|
|
|
|
+ {
|
|
|
|
+ WatchableObject watchableobject = (WatchableObject) arraylist.get( i );
|
|
|
|
+ if ( watchableobject.b() instanceof ItemStack )
|
|
|
|
+ {
|
|
|
|
+ watchableobject = new WatchableObject(
|
|
|
|
+ watchableobject.c(),
|
|
|
|
+ watchableobject.a(),
|
|
|
|
+ ( (ItemStack) watchableobject.b() ).cloneItemStack()
|
|
|
|
+ );
|
|
|
|
+ arraylist.set( i, watchableobject );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
|
|
|
|
this.f.readLock().unlock();
|
|
|
|
return arraylist;
|
2014-07-21 20:46:54 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
2015-02-28 11:36:22 +00:00
|
|
|
index 32af4ee..f426c2e 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
2015-02-28 11:36:22 +00:00
|
|
|
@@ -173,6 +173,10 @@ public class PacketDataSerializer extends ByteBuf {
|
2014-07-21 20:46:54 +00:00
|
|
|
NBTTagCompound nbttagcompound = null;
|
|
|
|
|
2014-11-28 01:17:45 +00:00
|
|
|
if (itemstack.getItem().usesDurability() || itemstack.getItem().p()) {
|
2014-07-21 20:46:54 +00:00
|
|
|
+ // Spigot start - filter
|
|
|
|
+ itemstack = itemstack.cloneItemStack();
|
|
|
|
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
|
|
|
|
+ // Spigot end
|
2014-11-28 01:17:45 +00:00
|
|
|
nbttagcompound = itemstack.getTag();
|
2014-07-21 20:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
2015-02-28 11:36:22 +00:00
|
|
|
index f23decd..13dbcd4 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
2014-12-27 22:07:04 +00:00
|
|
|
@@ -22,6 +22,10 @@ import net.minecraft.server.IChatBaseComponent;
|
2014-11-28 01:17:45 +00:00
|
|
|
import net.minecraft.server.NBTTagString;
|
|
|
|
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
+// 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");
|
2014-12-27 22:07:04 +00:00
|
|
|
@@ -57,11 +61,11 @@ class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
2014-07-21 20:46:54 +00:00
|
|
|
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
|
|
|
|
}
|
2014-12-13 04:47:57 +00:00
|
|
|
|
|
|
|
boolean resolved = false;
|
2014-12-27 22:07:04 +00:00
|
|
|
@@ -86,7 +90,7 @@ class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
2014-12-13 04:47:57 +00:00
|
|
|
// Ignore and treat as an old book
|
|
|
|
}
|
2014-11-28 01:17:45 +00:00
|
|
|
}
|
2014-12-27 22:07:04 +00:00
|
|
|
- addPage(page);
|
|
|
|
+ addPage( limit( page, 2048 ) ); // Spigot
|
2014-07-21 20:46:54 +00:00
|
|
|
}
|
2014-12-27 22:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-21 20:46:54 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2015-02-26 10:40:16 +00:00
|
|
|
index 661bc0c..84e6a74 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2015-02-15 01:52:33 +00:00
|
|
|
@@ -42,6 +42,10 @@ import java.util.EnumSet;
|
|
|
|
import java.util.HashSet;
|
2014-12-18 23:33:08 +00:00
|
|
|
import java.util.Set;
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
+// Spigot start
|
|
|
|
+import static org.spigotmc.ValidateUtils.*;
|
|
|
|
+// Spigot end
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Children must include the following:
|
|
|
|
*
|
2015-02-15 01:52:33 +00:00
|
|
|
@@ -245,7 +249,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-07-21 20:46:54 +00:00
|
|
|
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)) {
|
2015-02-15 01:52:33 +00:00
|
|
|
@@ -253,7 +257,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-07-21 20:46:54 +00:00
|
|
|
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 0000000..58a9534
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/org/spigotmc/ValidateUtils.java
|
|
|
|
@@ -0,0 +1,14 @@
|
|
|
|
+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;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
--
|
2014-11-28 01:17:45 +00:00
|
|
|
2.1.0
|
2014-07-21 20:46:54 +00:00
|
|
|
|