Paper/CraftBukkit-Patches/0143-Apply-NBTReadLimiter-to-more-things.patch
Zach Brown 19972e09b8 Update SpigotMC's patches
5a0150f586ed3eb15fe6f1f596d1a5a7d806f0f9 Fix ITEM_BREAK
e6a3911057bd94d8bd7021cbb4923fb84fb106d1 Upstream merge
d1cdcf8d4c3639f956474f02ed662517cffbe23e Remove old patch
068df64aeee368377e1673667bffc7a6dcf90554 Rebuild all patches
2014-11-30 16:16:48 -06:00

72 lines
2.1 KiB
Diff

From 1ae1dcab1312a51a4975680980d63f3f9f2d9026 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 27 Jul 2014 20:46:04 +1000
Subject: [PATCH] Apply NBTReadLimiter to more things.
diff --git a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
index e9d8828..14ba8df 100644
--- a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
+++ b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
@@ -48,6 +48,12 @@ public class NBTCompressedStreamTools {
public static NBTTagCompound a(DataInput datainput, NBTReadLimiter nbtreadlimiter) {
try {
+ // Spigot start
+ if ( datainput instanceof io.netty.buffer.ByteBufInputStream )
+ {
+ datainput = new DataInputStream(new org.spigotmc.LimitStream((InputStream) datainput, nbtreadlimiter));
+ }
+ // Spigot end
NBTBase nbtbase = a(datainput, 0, nbtreadlimiter);
if (nbtbase instanceof NBTTagCompound) {
diff --git a/src/main/java/org/spigotmc/LimitStream.java b/src/main/java/org/spigotmc/LimitStream.java
new file mode 100644
index 0000000..dcc0548
--- /dev/null
+++ b/src/main/java/org/spigotmc/LimitStream.java
@@ -0,0 +1,39 @@
+package org.spigotmc;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import net.minecraft.server.NBTReadLimiter;
+
+public class LimitStream extends FilterInputStream
+{
+
+ private final NBTReadLimiter limit;
+
+ public LimitStream(InputStream is, NBTReadLimiter limit)
+ {
+ super( is );
+ this.limit = limit;
+ }
+
+ @Override
+ public int read() throws IOException
+ {
+ limit.a( 1 );
+ return super.read();
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException
+ {
+ limit.a( b.length );
+ return super.read( b );
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException
+ {
+ limit.a( len );
+ return super.read( b, off, len );
+ }
+}
--
2.1.0