Improve NBTReadLimiter
This commit is contained in:
parent
fbc208645c
commit
ee319fcbb2
2 changed files with 225 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
From 43a4e7474c9544e427a446daac9b4b905e188450 Mon Sep 17 00:00:00 2001
|
From 118059e072f257722348916e04bfcad42abf20b2 Mon Sep 17 00:00:00 2001
|
||||||
From: md_5 <md_5@live.com.au>
|
From: md_5 <md_5@live.com.au>
|
||||||
Date: Sun, 1 Dec 2013 15:10:48 +1100
|
Date: Sun, 1 Dec 2013 15:10:48 +1100
|
||||||
Subject: [PATCH] mc-dev imports
|
Subject: [PATCH] mc-dev imports
|
||||||
|
@ -2724,6 +2724,213 @@ index 0000000..63c3bf9
|
||||||
+ return this.data;
|
+ return this.data;
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..e34c774
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
|
||||||
|
@@ -0,0 +1,201 @@
|
||||||
|
+package net.minecraft.server;
|
||||||
|
+
|
||||||
|
+import com.google.common.collect.Lists;
|
||||||
|
+import java.io.DataInput;
|
||||||
|
+import java.io.DataOutput;
|
||||||
|
+import java.io.IOException;
|
||||||
|
+import java.util.Iterator;
|
||||||
|
+import java.util.List;
|
||||||
|
+import org.apache.logging.log4j.LogManager;
|
||||||
|
+import org.apache.logging.log4j.Logger;
|
||||||
|
+
|
||||||
|
+public class NBTTagList extends NBTBase {
|
||||||
|
+
|
||||||
|
+ private static final Logger b = LogManager.getLogger();
|
||||||
|
+ private List<NBTBase> list = Lists.newArrayList();
|
||||||
|
+ private byte type = 0;
|
||||||
|
+
|
||||||
|
+ public NBTTagList() {}
|
||||||
|
+
|
||||||
|
+ void write(DataOutput dataoutput) throws IOException {
|
||||||
|
+ if (!this.list.isEmpty()) {
|
||||||
|
+ this.type = ((NBTBase) this.list.get(0)).getTypeId();
|
||||||
|
+ } else {
|
||||||
|
+ this.type = 0;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ dataoutput.writeByte(this.type);
|
||||||
|
+ dataoutput.writeInt(this.list.size());
|
||||||
|
+
|
||||||
|
+ for (int i = 0; i < this.list.size(); ++i) {
|
||||||
|
+ ((NBTBase) this.list.get(i)).write(dataoutput);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void load(DataInput datainput, int i, NBTReadLimiter nbtreadlimiter) throws IOException {
|
||||||
|
+ if (i > 512) {
|
||||||
|
+ throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
|
||||||
|
+ } else {
|
||||||
|
+ nbtreadlimiter.a(8L);
|
||||||
|
+ this.type = datainput.readByte();
|
||||||
|
+ int j = datainput.readInt();
|
||||||
|
+
|
||||||
|
+ this.list = Lists.newArrayList();
|
||||||
|
+
|
||||||
|
+ for (int k = 0; k < j; ++k) {
|
||||||
|
+ NBTBase nbtbase = NBTBase.createTag(this.type);
|
||||||
|
+
|
||||||
|
+ nbtbase.load(datainput, i + 1, nbtreadlimiter);
|
||||||
|
+ this.list.add(nbtbase);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public byte getTypeId() {
|
||||||
|
+ return (byte) 9;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public String toString() {
|
||||||
|
+ StringBuilder stringbuilder = new StringBuilder("[");
|
||||||
|
+
|
||||||
|
+ for (int i = 0; i < this.list.size(); ++i) {
|
||||||
|
+ if (i != 0) {
|
||||||
|
+ stringbuilder.append(',');
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ stringbuilder.append(i).append(':').append(this.list.get(i));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return stringbuilder.append(']').toString();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void add(NBTBase nbtbase) {
|
||||||
|
+ if (this.type == 0) {
|
||||||
|
+ this.type = nbtbase.getTypeId();
|
||||||
|
+ } else if (this.type != nbtbase.getTypeId()) {
|
||||||
|
+ NBTTagList.b.warn("Adding mismatching tag types to tag list");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ this.list.add(nbtbase);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void a(int i, NBTBase nbtbase) {
|
||||||
|
+ if (i >= 0 && i < this.list.size()) {
|
||||||
|
+ if (this.type == 0) {
|
||||||
|
+ this.type = nbtbase.getTypeId();
|
||||||
|
+ } else if (this.type != nbtbase.getTypeId()) {
|
||||||
|
+ NBTTagList.b.warn("Adding mismatching tag types to tag list");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ this.list.set(i, nbtbase);
|
||||||
|
+ } else {
|
||||||
|
+ NBTTagList.b.warn("index out of bounds to set tag in tag list");
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public NBTBase a(int i) {
|
||||||
|
+ return (NBTBase) this.list.remove(i);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public boolean isEmpty() {
|
||||||
|
+ return this.list.isEmpty();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public NBTTagCompound get(int i) {
|
||||||
|
+ if (i >= 0 && i < this.list.size()) {
|
||||||
|
+ NBTBase nbtbase = (NBTBase) this.list.get(i);
|
||||||
|
+
|
||||||
|
+ return nbtbase.getTypeId() == 10 ? (NBTTagCompound) nbtbase : new NBTTagCompound();
|
||||||
|
+ } else {
|
||||||
|
+ return new NBTTagCompound();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public int[] c(int i) {
|
||||||
|
+ if (i >= 0 && i < this.list.size()) {
|
||||||
|
+ NBTBase nbtbase = (NBTBase) this.list.get(i);
|
||||||
|
+
|
||||||
|
+ return nbtbase.getTypeId() == 11 ? ((NBTTagIntArray) nbtbase).c() : new int[0];
|
||||||
|
+ } else {
|
||||||
|
+ return new int[0];
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public double d(int i) {
|
||||||
|
+ if (i >= 0 && i < this.list.size()) {
|
||||||
|
+ NBTBase nbtbase = (NBTBase) this.list.get(i);
|
||||||
|
+
|
||||||
|
+ return nbtbase.getTypeId() == 6 ? ((NBTTagDouble) nbtbase).g() : 0.0D;
|
||||||
|
+ } else {
|
||||||
|
+ return 0.0D;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public float e(int i) {
|
||||||
|
+ if (i >= 0 && i < this.list.size()) {
|
||||||
|
+ NBTBase nbtbase = (NBTBase) this.list.get(i);
|
||||||
|
+
|
||||||
|
+ return nbtbase.getTypeId() == 5 ? ((NBTTagFloat) nbtbase).h() : 0.0F;
|
||||||
|
+ } else {
|
||||||
|
+ return 0.0F;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public String getString(int i) {
|
||||||
|
+ if (i >= 0 && i < this.list.size()) {
|
||||||
|
+ NBTBase nbtbase = (NBTBase) this.list.get(i);
|
||||||
|
+
|
||||||
|
+ return nbtbase.getTypeId() == 8 ? nbtbase.a_() : nbtbase.toString();
|
||||||
|
+ } else {
|
||||||
|
+ return "";
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public NBTBase g(int i) {
|
||||||
|
+ return (NBTBase) (i >= 0 && i < this.list.size() ? (NBTBase) this.list.get(i) : new NBTTagEnd());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public int size() {
|
||||||
|
+ return this.list.size();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public NBTBase clone() {
|
||||||
|
+ NBTTagList nbttaglist = new NBTTagList();
|
||||||
|
+
|
||||||
|
+ nbttaglist.type = this.type;
|
||||||
|
+ Iterator iterator = this.list.iterator();
|
||||||
|
+
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ NBTBase nbtbase = (NBTBase) iterator.next();
|
||||||
|
+ NBTBase nbtbase1 = nbtbase.clone();
|
||||||
|
+
|
||||||
|
+ nbttaglist.list.add(nbtbase1);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return nbttaglist;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public boolean equals(Object object) {
|
||||||
|
+ if (super.equals(object)) {
|
||||||
|
+ NBTTagList nbttaglist = (NBTTagList) object;
|
||||||
|
+
|
||||||
|
+ if (this.type == nbttaglist.type) {
|
||||||
|
+ return this.list.equals(nbttaglist.list);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public int hashCode() {
|
||||||
|
+ return super.hashCode() ^ this.list.hashCode();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public int f() {
|
||||||
|
+ return this.type;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
diff --git a/src/main/java/net/minecraft/server/NextTickListEntry.java b/src/main/java/net/minecraft/server/NextTickListEntry.java
|
diff --git a/src/main/java/net/minecraft/server/NextTickListEntry.java b/src/main/java/net/minecraft/server/NextTickListEntry.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..648d255
|
index 0000000..648d255
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
From 662708146f4d997487386cec459b5dee536d0bea Mon Sep 17 00:00:00 2001
|
From 0a7fd3a0aff060a3332b562618f35b7b2fbec834 Mon Sep 17 00:00:00 2001
|
||||||
From: md_5 <git@md-5.net>
|
From: md_5 <git@md-5.net>
|
||||||
Date: Sun, 27 Jul 2014 20:46:04 +1000
|
Date: Sun, 27 Jul 2014 20:46:04 +1000
|
||||||
Subject: [PATCH] Apply NBTReadLimiter to more things.
|
Subject: [PATCH] Apply NBTReadLimiter to more things.
|
||||||
|
@ -21,9 +21,21 @@ index 2a04b86..b2d5254 100644
|
||||||
NBTBase nbtbase = a(datainput, 0, nbtreadlimiter);
|
NBTBase nbtbase = a(datainput, 0, nbtreadlimiter);
|
||||||
|
|
||||||
if (nbtbase instanceof NBTTagCompound) {
|
if (nbtbase instanceof NBTTagCompound) {
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
|
||||||
|
index e34c774..6d91deb 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/NBTTagList.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
|
||||||
|
@@ -45,6 +45,7 @@ public class NBTTagList extends NBTBase {
|
||||||
|
|
||||||
|
for (int k = 0; k < j; ++k) {
|
||||||
|
NBTBase nbtbase = NBTBase.createTag(this.type);
|
||||||
|
+ nbtreadlimiter.a(8); // Spigot
|
||||||
|
|
||||||
|
nbtbase.load(datainput, i + 1, nbtreadlimiter);
|
||||||
|
this.list.add(nbtbase);
|
||||||
diff --git a/src/main/java/org/spigotmc/LimitStream.java b/src/main/java/org/spigotmc/LimitStream.java
|
diff --git a/src/main/java/org/spigotmc/LimitStream.java b/src/main/java/org/spigotmc/LimitStream.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..dcc0548
|
index 0000000..8c32e8b
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/org/spigotmc/LimitStream.java
|
+++ b/src/main/java/org/spigotmc/LimitStream.java
|
||||||
@@ -0,0 +1,39 @@
|
@@ -0,0 +1,39 @@
|
||||||
|
@ -48,21 +60,21 @@ index 0000000..dcc0548
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public int read() throws IOException
|
+ public int read() throws IOException
|
||||||
+ {
|
+ {
|
||||||
+ limit.a( 1 );
|
+ limit.a( 8 );
|
||||||
+ return super.read();
|
+ return super.read();
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public int read(byte[] b) throws IOException
|
+ public int read(byte[] b) throws IOException
|
||||||
+ {
|
+ {
|
||||||
+ limit.a( b.length );
|
+ limit.a( b.length * 8 );
|
||||||
+ return super.read( b );
|
+ return super.read( b );
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public int read(byte[] b, int off, int len) throws IOException
|
+ public int read(byte[] b, int off, int len) throws IOException
|
||||||
+ {
|
+ {
|
||||||
+ limit.a( len );
|
+ limit.a( len * 8 );
|
||||||
+ return super.read( b, off, len );
|
+ return super.read( b, off, len );
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
|
|
Loading…
Reference in a new issue