mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-01 04:37:09 +00:00
111 lines
3.6 KiB
Diff
111 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Allink <arclicious@vivaldi.net>
|
|
Date: Fri, 2 Jun 2023 22:13:54 +0100
|
|
Subject: [PATCH] Add depth limit to SNBT
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/nbt/TagParser.java b/src/main/java/net/minecraft/nbt/TagParser.java
|
|
index fbfe810e8be6cb159742f7fd85e7491b9cefa4dc..b70bafe2766efcbcce00287e6511a588560564a6 100644
|
|
--- a/src/main/java/net/minecraft/nbt/TagParser.java
|
|
+++ b/src/main/java/net/minecraft/nbt/TagParser.java
|
|
@@ -169,9 +169,56 @@ public class TagParser {
|
|
}
|
|
|
|
this.expect('}');
|
|
- return compoundTag;
|
|
+ return exceedsDepthLimit(compoundTag) ? new CompoundTag() : compoundTag; // Scissors - Add depth limit to SNBT
|
|
}
|
|
|
|
+ // Scissors start - Add depth limit to SNBT
|
|
+ private boolean exceedsDepthLimit(Tag tag) {
|
|
+ return this.exceedsDepthLimit(0, tag);
|
|
+ }
|
|
+
|
|
+ private boolean exceedsDepthLimit(long depth, Tag tag)
|
|
+ {
|
|
+ if (depth > 256)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ if (tag instanceof ListTag listTag)
|
|
+ {
|
|
+ for (Tag childTag : listTag)
|
|
+ {
|
|
+ boolean returnValue = this.exceedsDepthLimit(depth + 1, childTag);
|
|
+
|
|
+ if (returnValue)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ } else if (tag instanceof CompoundTag compoundTag)
|
|
+ {
|
|
+ for (String key: compoundTag.getAllKeys())
|
|
+ {
|
|
+ Tag childTag = compoundTag.get(key);
|
|
+
|
|
+ if (childTag == null)
|
|
+ {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ boolean returnValue = this.exceedsDepthLimit(depth + 1, childTag);
|
|
+
|
|
+ if (returnValue)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+ // Scissors end
|
|
+
|
|
private Tag readListTag() throws CommandSyntaxException {
|
|
this.expect('[');
|
|
this.reader.skipWhitespace();
|
|
@@ -203,7 +250,7 @@ public class TagParser {
|
|
}
|
|
|
|
this.expect(']');
|
|
- return listTag;
|
|
+ return exceedsDepthLimit(listTag) ? new ListTag() : listTag; // Scissors - Add depth limit to SNBT
|
|
}
|
|
}
|
|
|
|
@@ -228,7 +275,7 @@ public class TagParser {
|
|
}
|
|
|
|
private <T extends Number> List<T> readArray(TagType<?> arrayTypeReader, TagType<?> typeReader) throws CommandSyntaxException {
|
|
- List<T> list = Lists.newArrayList();
|
|
+ List<Number> list = Lists.newArrayList(); // Scissors - List<T> -> List<Number>
|
|
|
|
while(true) {
|
|
if (this.reader.peek() != ']') {
|
|
@@ -241,11 +288,11 @@ public class TagParser {
|
|
}
|
|
|
|
if (typeReader == ByteTag.TYPE) {
|
|
- list.add((T)((NumericTag)tag).getAsByte());
|
|
+ list.add(((NumericTag)tag).getAsByte()); // Scissors - Remove (T) cast
|
|
} else if (typeReader == LongTag.TYPE) {
|
|
- list.add((T)((NumericTag)tag).getAsLong());
|
|
+ list.add(((NumericTag)tag).getAsLong()); // Scissors - Remove (T) cast
|
|
} else {
|
|
- list.add((T)((NumericTag)tag).getAsInt());
|
|
+ list.add(((NumericTag)tag).getAsInt()); // Scissors - Remove (T) cast
|
|
}
|
|
|
|
if (this.hasElementSeparator()) {
|
|
@@ -257,7 +304,7 @@ public class TagParser {
|
|
}
|
|
|
|
this.expect(']');
|
|
- return list;
|
|
+ return (List<T>) list; // Scissors - Cast to List<T>
|
|
}
|
|
}
|
|
|