mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-06-30 22:11:46 +00:00
65d7993679
* First pass * Second and final pass * Update Jenkinsfile
143 lines
7.7 KiB
Diff
143 lines
7.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Luna <lunahatesgogle@gmail.com>
|
|
Date: Fri, 8 Apr 2022 23:38:12 -0300
|
|
Subject: [PATCH] Limit string tag visitors to 1024 elements
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/nbt/SnbtPrinterTagVisitor.java b/src/main/java/net/minecraft/nbt/SnbtPrinterTagVisitor.java
|
|
index e07cc7970955ce240754cfe424d768c2bba0241a..a4f41bb4ec6cb20f782668c714229b61415cfdfb 100644
|
|
--- a/src/main/java/net/minecraft/nbt/SnbtPrinterTagVisitor.java
|
|
+++ b/src/main/java/net/minecraft/nbt/SnbtPrinterTagVisitor.java
|
|
@@ -89,6 +89,7 @@ public class SnbtPrinterTagVisitor implements TagVisitor {
|
|
public void visitByteArray(ByteArrayTag element) {
|
|
StringBuilder stringBuilder = (new StringBuilder("[")).append("B").append(";");
|
|
byte[] bs = element.getAsByteArray();
|
|
+ if (bs.length > 1024) { this.result = stringBuilder.append("]").toString(); return; } // Scissors
|
|
|
|
for(int i = 0; i < bs.length; ++i) {
|
|
stringBuilder.append(" ").append((int)bs[i]).append("B");
|
|
@@ -105,6 +106,7 @@ public class SnbtPrinterTagVisitor implements TagVisitor {
|
|
public void visitIntArray(IntArrayTag element) {
|
|
StringBuilder stringBuilder = (new StringBuilder("[")).append("I").append(";");
|
|
int[] is = element.getAsIntArray();
|
|
+ if (is.length > 1024) { this.result = stringBuilder.append("]").toString(); return; } // Scissors
|
|
|
|
for(int i = 0; i < is.length; ++i) {
|
|
stringBuilder.append(" ").append(is[i]);
|
|
@@ -122,6 +124,7 @@ public class SnbtPrinterTagVisitor implements TagVisitor {
|
|
String string = "L";
|
|
StringBuilder stringBuilder = (new StringBuilder("[")).append("L").append(";");
|
|
long[] ls = element.getAsLongArray();
|
|
+ if (ls.length > 1024) { this.result = stringBuilder.append("]").toString(); return; } // Scissors
|
|
|
|
for(int i = 0; i < ls.length; ++i) {
|
|
stringBuilder.append(" ").append(ls[i]).append("L");
|
|
@@ -136,7 +139,7 @@ public class SnbtPrinterTagVisitor implements TagVisitor {
|
|
|
|
@Override
|
|
public void visitList(ListTag element) {
|
|
- if (element.isEmpty()) {
|
|
+ if (element.isEmpty() || element.size() > 1024) { // Scissors
|
|
this.result = "[]";
|
|
} else {
|
|
StringBuilder stringBuilder = new StringBuilder("[");
|
|
@@ -166,7 +169,7 @@ public class SnbtPrinterTagVisitor implements TagVisitor {
|
|
|
|
@Override
|
|
public void visitCompound(CompoundTag compound) {
|
|
- if (compound.isEmpty()) {
|
|
+ if (compound.isEmpty() || compound.size() > 1024) { // Scissors
|
|
this.result = "{}";
|
|
} else {
|
|
StringBuilder stringBuilder = new StringBuilder("{");
|
|
diff --git a/src/main/java/net/minecraft/nbt/StringTagVisitor.java b/src/main/java/net/minecraft/nbt/StringTagVisitor.java
|
|
index a687a0f17df30126d53a1e3a669dc6d157c23ed5..2c50f41dd8034af16fcceca75eeb6c7a9940e327 100644
|
|
--- a/src/main/java/net/minecraft/nbt/StringTagVisitor.java
|
|
+++ b/src/main/java/net/minecraft/nbt/StringTagVisitor.java
|
|
@@ -53,6 +53,7 @@ public class StringTagVisitor implements TagVisitor {
|
|
public void visitByteArray(ByteArrayTag element) {
|
|
this.builder.append("[B;");
|
|
byte[] bs = element.getAsByteArray();
|
|
+ if (bs.length > 1024) { this.builder.append(']'); return; } // Scissors
|
|
|
|
for(int i = 0; i < bs.length; ++i) {
|
|
if (i != 0) {
|
|
@@ -69,6 +70,7 @@ public class StringTagVisitor implements TagVisitor {
|
|
public void visitIntArray(IntArrayTag element) {
|
|
this.builder.append("[I;");
|
|
int[] is = element.getAsIntArray();
|
|
+ if (is.length > 1024) { this.builder.append(']'); return; } // Scissors
|
|
|
|
for(int i = 0; i < is.length; ++i) {
|
|
if (i != 0) {
|
|
@@ -85,6 +87,7 @@ public class StringTagVisitor implements TagVisitor {
|
|
public void visitLongArray(LongArrayTag element) {
|
|
this.builder.append("[L;");
|
|
long[] ls = element.getAsLongArray();
|
|
+ if (ls.length > 1024) { this.builder.append(']'); return; } // Scissors
|
|
|
|
for(int i = 0; i < ls.length; ++i) {
|
|
if (i != 0) {
|
|
@@ -100,6 +103,7 @@ public class StringTagVisitor implements TagVisitor {
|
|
@Override
|
|
public void visitList(ListTag element) {
|
|
this.builder.append('[');
|
|
+ if (element.size() > 1024) { this.builder.append(']'); return; } // Scissors
|
|
|
|
for(int i = 0; i < element.size(); ++i) {
|
|
if (i != 0) {
|
|
@@ -116,6 +120,7 @@ public class StringTagVisitor implements TagVisitor {
|
|
public void visitCompound(CompoundTag compound) {
|
|
this.builder.append('{');
|
|
List<String> list = Lists.newArrayList(compound.getAllKeys());
|
|
+ if (list.size() > 1024) { this.builder.append('}'); return; } // Scissors
|
|
Collections.sort(list);
|
|
|
|
for(String string : list) {
|
|
diff --git a/src/main/java/net/minecraft/nbt/TextComponentTagVisitor.java b/src/main/java/net/minecraft/nbt/TextComponentTagVisitor.java
|
|
index 149def3da0b92f64e4fc04630965dce44884f938..c9d753f37bd65e35f8a4e2eb5c6fe8f74d5d1606 100644
|
|
--- a/src/main/java/net/minecraft/nbt/TextComponentTagVisitor.java
|
|
+++ b/src/main/java/net/minecraft/nbt/TextComponentTagVisitor.java
|
|
@@ -97,6 +97,7 @@ public class TextComponentTagVisitor implements TagVisitor {
|
|
Component component = Component.literal("B").withStyle(SYNTAX_HIGHLIGHTING_NUMBER_TYPE);
|
|
MutableComponent mutableComponent = Component.literal("[").append(component).append(";");
|
|
byte[] bs = element.getAsByteArray();
|
|
+ if (bs.length > 1024) { this.result = mutableComponent.append("]"); return; } // Scissors
|
|
|
|
for(int i = 0; i < bs.length; ++i) {
|
|
MutableComponent mutableComponent2 = Component.literal(String.valueOf((int)bs[i])).withStyle(SYNTAX_HIGHLIGHTING_NUMBER);
|
|
@@ -115,6 +116,7 @@ public class TextComponentTagVisitor implements TagVisitor {
|
|
Component component = Component.literal("I").withStyle(SYNTAX_HIGHLIGHTING_NUMBER_TYPE);
|
|
MutableComponent mutableComponent = Component.literal("[").append(component).append(";");
|
|
int[] is = element.getAsIntArray();
|
|
+ if (is.length > 1024) { this.result = mutableComponent.append("]"); return; } // Scissors
|
|
|
|
for(int i = 0; i < is.length; ++i) {
|
|
mutableComponent.append(" ").append(Component.literal(String.valueOf(is[i])).withStyle(SYNTAX_HIGHLIGHTING_NUMBER));
|
|
@@ -132,6 +134,7 @@ public class TextComponentTagVisitor implements TagVisitor {
|
|
Component component = Component.literal("L").withStyle(SYNTAX_HIGHLIGHTING_NUMBER_TYPE);
|
|
MutableComponent mutableComponent = Component.literal("[").append(component).append(";");
|
|
long[] ls = element.getAsLongArray();
|
|
+ if (ls.length > 1024) { this.result = mutableComponent.append("]"); return; } // Scissors
|
|
|
|
for(int i = 0; i < ls.length; ++i) {
|
|
Component component2 = Component.literal(String.valueOf(ls[i])).withStyle(SYNTAX_HIGHLIGHTING_NUMBER);
|
|
@@ -147,7 +150,7 @@ public class TextComponentTagVisitor implements TagVisitor {
|
|
|
|
@Override
|
|
public void visitList(ListTag element) {
|
|
- if (element.isEmpty()) {
|
|
+ if (element.isEmpty() || element.size() > 1024) { // Scissors
|
|
this.result = Component.literal("[]");
|
|
} else if (INLINE_ELEMENT_TYPES.contains(element.getElementType()) && element.size() <= 8) {
|
|
String string = ELEMENT_SEPARATOR + " ";
|
|
@@ -190,7 +193,7 @@ public class TextComponentTagVisitor implements TagVisitor {
|
|
|
|
@Override
|
|
public void visitCompound(CompoundTag compound) {
|
|
- if (compound.isEmpty()) {
|
|
+ if (compound.isEmpty() || compound.size() > 1024) { // Scissors
|
|
this.result = Component.literal("{}");
|
|
} else {
|
|
MutableComponent mutableComponent = Component.literal("{");
|