Scissors/patches/server/0029-Reject-oversized-components-from-updating.patch

47 lines
2.4 KiB
Diff
Raw Normal View History

2022-06-12 05:35:09 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2022-06-19 02:42:47 +00:00
From: Video <videogamesm12@gmail.com>
2022-06-12 05:35:09 +00:00
Date: Sun, 12 Jun 2022 00:33:21 -0500
Subject: [PATCH] Reject oversized components from updating
diff --git a/src/main/java/net/minecraft/network/chat/ComponentUtils.java b/src/main/java/net/minecraft/network/chat/ComponentUtils.java
index 9d3449dd92bbbef91b627caba752b87d8209011d..e162fb748745ec50189e426c2de5a91ce618be1b 100644
2022-06-12 05:35:09 +00:00
--- a/src/main/java/net/minecraft/network/chat/ComponentUtils.java
+++ b/src/main/java/net/minecraft/network/chat/ComponentUtils.java
@@ -39,8 +39,10 @@ public class ComponentUtils {
}
public static MutableComponent updateForEntity(@Nullable CommandSourceStack source, Component text, @Nullable Entity sender, int depth) throws CommandSyntaxException {
+ // Scissors start - Reject oversized components
+ MutableComponent result;
if (depth > 100) {
- return text.copy();
+ result = text.copy();
} else {
MutableComponent mutableComponent = text.getContents().resolve(source, sender, depth + 1);
@@ -48,8 +50,11 @@ public class ComponentUtils {
mutableComponent.append(updateForEntity(source, component, sender, depth + 1));
}
- return mutableComponent.withStyle(resolveStyle(source, text.getStyle(), sender, depth));
+ result = mutableComponent.withStyle(resolveStyle(source, text.getStyle(), sender, depth));
}
+ // Would the resulting component exceed 65535 bytes when encoded as a string?
+ return Component.Serializer.toJson(result).length() > 65535 ? Component.empty() : result;
+ // Scissors end
}
private static Style resolveStyle(@Nullable CommandSourceStack source, Style style, @Nullable Entity sender, int depth) throws CommandSyntaxException {
@@ -138,8 +143,8 @@ public class ComponentUtils {
ComponentContents string = text.getContents();
if (string instanceof TranslatableContents) {
TranslatableContents translatableContents = (TranslatableContents)string;
- String string = translatableContents.getKey();
- return Language.getInstance().has(string);
+ String string1 = translatableContents.getKey();
+ return Language.getInstance().has(string1);
}
}