2023-06-02 22:07:55 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2024-04-16 05:12:25 +00:00
|
|
|
From: Telesphoreo <me@telesphoreo.me>
|
|
|
|
Date: Mon, 15 Apr 2024 23:40:27 -0500
|
2023-06-02 22:07:55 +00:00
|
|
|
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
|
2024-04-16 05:12:25 +00:00
|
|
|
index c77860a141064aea6a0b510bb44d35fea90aee42..3be3dd61b8a27b3a8ca3c72ae5ffa2ea8fa00231 100644
|
2023-06-02 22:07:55 +00:00
|
|
|
--- a/src/main/java/net/minecraft/nbt/TagParser.java
|
|
|
|
+++ b/src/main/java/net/minecraft/nbt/TagParser.java
|
2024-04-16 05:12:25 +00:00
|
|
|
@@ -184,9 +184,47 @@ public class TagParser {
|
2023-06-02 22:07:55 +00:00
|
|
|
|
|
|
|
this.expect('}');
|
2024-02-11 01:15:15 +00:00
|
|
|
this.depth--; // Paper
|
2023-06-02 22:07:55 +00:00
|
|
|
- return compoundTag;
|
2023-07-01 20:21:13 +00:00
|
|
|
+ return exceedsDepthLimit(compoundTag) ? new CompoundTag() : compoundTag; // Scissors - Add depth limit to SNBT
|
|
|
|
}
|
|
|
|
|
2023-06-02 22:07:55 +00:00
|
|
|
+ // Scissors start - Add depth limit to SNBT
|
|
|
|
+ private boolean exceedsDepthLimit(Tag tag) {
|
|
|
|
+ return this.exceedsDepthLimit(0, tag);
|
|
|
|
+ }
|
|
|
|
+
|
2024-04-16 05:12:25 +00:00
|
|
|
+ private boolean exceedsDepthLimit(long depth, Tag tag) {
|
|
|
|
+ if (depth > 256) {
|
2023-06-02 22:07:55 +00:00
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
2024-04-16 05:12:25 +00:00
|
|
|
+ if (tag instanceof ListTag listTag) {
|
|
|
|
+ for (Tag childTag : listTag) {
|
2023-06-02 22:07:55 +00:00
|
|
|
+ boolean returnValue = this.exceedsDepthLimit(depth + 1, childTag);
|
|
|
|
+
|
2024-04-16 05:12:25 +00:00
|
|
|
+ if (returnValue) {
|
2023-06-02 22:07:55 +00:00
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
2024-04-16 05:12:25 +00:00
|
|
|
+ } else if (tag instanceof CompoundTag compoundTag) {
|
|
|
|
+ for (String key : compoundTag.getAllKeys()) {
|
2023-06-02 22:07:55 +00:00
|
|
|
+ Tag childTag = compoundTag.get(key);
|
|
|
|
+
|
2024-04-16 05:12:25 +00:00
|
|
|
+ if (childTag == null) {
|
2023-06-02 22:07:55 +00:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ boolean returnValue = this.exceedsDepthLimit(depth + 1, childTag);
|
|
|
|
+
|
2024-04-16 05:12:25 +00:00
|
|
|
+ if (returnValue) {
|
2023-06-02 22:07:55 +00:00
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
2023-07-01 20:21:13 +00:00
|
|
|
+ }
|
2023-06-02 22:07:55 +00:00
|
|
|
+ // Scissors end
|
2023-07-01 20:21:13 +00:00
|
|
|
+
|
2023-06-02 22:07:55 +00:00
|
|
|
private Tag readListTag() throws CommandSyntaxException {
|
|
|
|
this.expect('[');
|
2023-07-01 20:21:13 +00:00
|
|
|
this.reader.skipWhitespace();
|
2024-04-16 05:12:25 +00:00
|
|
|
@@ -220,7 +258,7 @@ public class TagParser {
|
2023-06-02 22:07:55 +00:00
|
|
|
|
|
|
|
this.expect(']');
|
2024-02-11 01:15:15 +00:00
|
|
|
this.depth--; // Paper
|
2023-06-02 22:07:55 +00:00
|
|
|
- return listTag;
|
2023-07-01 20:21:13 +00:00
|
|
|
+ return exceedsDepthLimit(listTag) ? new ListTag() : listTag; // Scissors - Add depth limit to SNBT
|
2023-06-02 22:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-16 05:12:25 +00:00
|
|
|
@@ -245,7 +283,7 @@ public class TagParser {
|
2023-06-02 22:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
2024-04-16 05:12:25 +00:00
|
|
|
while (this.reader.peek() != ']') {
|
|
|
|
int i = this.reader.getCursor();
|
|
|
|
@@ -257,11 +295,11 @@ public class TagParser {
|
|
|
|
}
|
2023-06-02 22:07:55 +00:00
|
|
|
|
2024-04-16 05:12:25 +00:00
|
|
|
if (typeReader == ByteTag.TYPE) {
|
|
|
|
- list.add((T)(Byte)((NumericTag)tag).getAsByte()); // Paper - decompile fix
|
|
|
|
+ list.add(((NumericTag)tag).getAsByte()); // Scissors - Remove (T) cast
|
|
|
|
} else if (typeReader == LongTag.TYPE) {
|
|
|
|
- list.add((T)(Long)((NumericTag)tag).getAsLong()); // Paper - decompile fix
|
|
|
|
+ list.add(((NumericTag)tag).getAsLong()); // Scissors - Remove (T) cast
|
|
|
|
} else {
|
|
|
|
- list.add((T)(Integer)((NumericTag)tag).getAsInt()); // Paper - decompile fix
|
|
|
|
+ list.add(((NumericTag)tag).getAsInt()); // Scissors - Remove (T) cast
|
2023-06-02 22:07:55 +00:00
|
|
|
}
|
|
|
|
|
2024-04-16 05:12:25 +00:00
|
|
|
if (!this.hasElementSeparator()) {
|
|
|
|
@@ -274,7 +312,7 @@ public class TagParser {
|
2023-06-02 22:07:55 +00:00
|
|
|
}
|
2024-04-16 05:12:25 +00:00
|
|
|
|
|
|
|
this.expect(']');
|
|
|
|
- return list;
|
|
|
|
+ return (List<T>) list; // Scissors - Cast to List<T>
|
2023-06-02 22:07:55 +00:00
|
|
|
}
|
|
|
|
|
2024-04-16 05:12:25 +00:00
|
|
|
private boolean hasElementSeparator() {
|