spigot/CraftBukkit-Patches/0069-Apply-NBTReadLimiter-to-more-things.patch

72 lines
2.1 KiB
Diff
Raw Normal View History

From e8aaebc951477889b0e03477dd8b02c2c83b63dd Mon Sep 17 00:00:00 2001
2014-07-27 20:46:24 +10:00
From: md_5 <git@md-5.net>
Date: Sun, 27 Jul 2014 20:46:04 +1000
Subject: [PATCH] Apply NBTReadLimiter to more things.
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/nbt/NBTCompressedStreamTools.java b/src/main/java/net/minecraft/nbt/NBTCompressedStreamTools.java
index 392598dce..438b56859 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/nbt/NBTCompressedStreamTools.java
+++ b/src/main/java/net/minecraft/nbt/NBTCompressedStreamTools.java
2022-03-01 02:00:00 +11:00
@@ -229,6 +229,12 @@ public class NBTCompressedStreamTools {
2015-02-28 11:36:22 +00:00
}
2014-07-27 20:46:24 +10:00
2021-11-22 09:00:00 +11:00
public static NBTTagCompound read(DataInput datainput, NBTReadLimiter nbtreadlimiter) throws IOException {
+ // Spigot start
+ if ( datainput instanceof io.netty.buffer.ByteBufInputStream )
+ {
+ datainput = new DataInputStream(new org.spigotmc.LimitStream((InputStream) datainput, nbtreadlimiter));
+ }
+ // Spigot end
2021-11-22 09:00:00 +11:00
NBTBase nbtbase = readUnnamedTag(datainput, 0, nbtreadlimiter);
2014-07-27 20:46:24 +10:00
if (nbtbase instanceof NBTTagCompound) {
2014-07-27 20:46:24 +10:00
diff --git a/src/main/java/org/spigotmc/LimitStream.java b/src/main/java/org/spigotmc/LimitStream.java
new file mode 100644
index 000000000..e74c61ca9
2014-07-27 20:46:24 +10:00
--- /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;
2021-03-16 09:00:00 +11:00
+import net.minecraft.nbt.NBTReadLimiter;
2014-07-27 20:46:24 +10:00
+
+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
+ {
2022-12-08 03:00:00 +11:00
+ limit.accountBytes( 1 );
2014-07-27 20:46:24 +10:00
+ return super.read();
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException
+ {
2022-12-08 03:00:00 +11:00
+ limit.accountBytes( b.length );
2014-07-27 20:46:24 +10:00
+ return super.read( b );
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException
+ {
2022-12-08 03:00:00 +11:00
+ limit.accountBytes( len );
2014-07-27 20:46:24 +10:00
+ return super.read( b, off, len );
+ }
+}
--
2023-06-08 01:30:00 +10:00
2.40.1
2014-07-27 20:46:24 +10:00