13
0
geforkt von Mirrors/Paper
Paper/CraftBukkit-Patches/0149-Better-item-validation.patch
Zach Brown 398f6983bd Update from upstream SpigotMC
Make "moved too quickly" limit configurable SpigotMC/Spigot@99a0a640e8
Undeprecate Player#updateInventory()V SpigotMC/Spigot@5c32e1cb48
Fetch complete profile for skull items, similarly to TileEntitySkull. SpigotMC/Spigot@33d758773e
Move getDouble into the Spigot Configuration patch SpigotMC/Spigot@b5dd202af1
Add missing particle to particle API SpigotMC/Spigot@273c64bbad
Log debug levels to the log file. SpigotMC/Spigot@348eae75f4
Fix PlayerItemDamageEvent (we already had this #badupstreamrelations) SpigotMC/Spigot@e207ea23cd
Move hopper patch to top for PR180 SpigotMC/Spigot@abb775108d
Don't be so spammy on Java 6 SpigotMC/Spigot@5abb82b1ca
Apply NBTReadLimiter to more things SpigotMC/Spigot@408944e9f5
2014-07-27 14:20:28 -05:00

116 Zeilen
4.5 KiB
Diff

From 596be8ab109b740acdc0441131552d2ffa2046cd 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 a5be533..e4df5b3 100644
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
@@ -97,6 +97,10 @@ 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 1cf8fce..bdc6364 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
@@ -17,6 +17,10 @@ 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");
@@ -45,11 +49,11 @@ 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)) {
@@ -57,7 +61,7 @@ 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 c9738c4..ec37524 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -36,6 +36,10 @@ 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:
*
@@ -227,7 +231,7 @@ 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)) {
@@ -235,7 +239,7 @@ 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 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;
+ }
+}
--
1.9.1