This is it, all patches applied

Now to see if they all work
This commit is contained in:
Telesphoreo 2022-04-22 02:03:09 -05:00
parent 7081efe798
commit 823057089b
7 changed files with 195 additions and 0 deletions

View File

@ -0,0 +1,37 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Video <videogamesm12@gmail.com>
Date: Mon, 28 Mar 2022 16:49:17 -0600
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 8f4c83837d0b01a3dbca2607ea718c371db48ef4..fe2717679f84fbef1b8ff1f9a3c3bf0fba8965f1 100644
--- a/src/main/java/net/minecraft/network/chat/ComponentUtils.java
+++ b/src/main/java/net/minecraft/network/chat/ComponentUtils.java
@@ -37,8 +37,11 @@ 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 instanceof ContextAwareComponent ? ((ContextAwareComponent)text).resolve(source, sender, depth + 1) : text.plainCopy();
@@ -46,8 +49,12 @@ 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 ? new TextComponent("") : result;
+ // Scissors end
}
private static Style resolveStyle(@Nullable CommandSourceStack source, Style style, @Nullable Entity sender, int depth) throws CommandSyntaxException {

View File

@ -0,0 +1,158 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Telesphoreo <me@telesphoreo.me>
Date: Fri, 22 Apr 2022 01:56:03 -0500
Subject: [PATCH] Reset large tags
diff --git a/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java b/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java
new file mode 100644
index 0000000000000000000000000000000000000000..058203440fd071ce5edbe18391ea60f0a5fbee3a
--- /dev/null
+++ b/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java
@@ -0,0 +1,28 @@
+package com.github.atlasmediagroup.scissors;
+
+import net.minecraft.nbt.CompoundTag;
+
+import javax.annotation.Nullable;
+import java.nio.charset.StandardCharsets;
+
+public class NbtUtility
+{
+
+ public static boolean isTooLarge(@Nullable CompoundTag tag)
+ {
+ if (tag == null) return false;
+ return tag.toString().getBytes(StandardCharsets.UTF_8).length > (256 * 1024);
+ }
+
+ public static class Item
+ {
+
+ public static CompoundTag removeItemData(CompoundTag tag)
+ {
+ CompoundTag cleaned = new CompoundTag();
+ cleaned.putString("id", tag.getString("id"));
+ cleaned.putByte("Count", tag.getByte("Count"));
+ return cleaned;
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 6837c965592d4584cfc958a1008b98791a0fc780..0f7d7248be0aa99dd759d12ed956a98822a2749b 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -1,5 +1,6 @@
package net.minecraft.world.item;
+import com.github.atlasmediagroup.scissors.NbtUtility;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@@ -8,13 +9,13 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
+import com.mojang.serialization.Dynamic;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map.Entry;
@@ -50,11 +51,7 @@ import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
-import net.minecraft.world.entity.Entity;
-import net.minecraft.world.entity.EquipmentSlot;
-import net.minecraft.world.entity.LivingEntity;
-import net.minecraft.world.entity.MobType;
-import net.minecraft.world.entity.SlotAccess;
+import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
@@ -75,8 +72,6 @@ import net.minecraft.world.level.block.Block;
import org.slf4j.Logger;
// CraftBukkit start
-import com.mojang.serialization.Dynamic;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
import net.minecraft.server.MinecraftServer;
@@ -251,6 +246,13 @@ public final class ItemStack {
// CraftBukkit - break into own method
private void load(CompoundTag nbttagcompound) {
+ // Scissors start - Reset large tags
+ if (NbtUtility.isTooLarge(nbttagcompound)) {
+ // Reset tag without destroying item
+ nbttagcompound = NbtUtility.Item.removeItemData(nbttagcompound);
+ }
+ // Scissors end
+
this.item = (Item) Registry.ITEM.get(new ResourceLocation(nbttagcompound.getString("id")));
this.count = nbttagcompound.getByte("Count");
if (nbttagcompound.contains("tag", 10)) {
@@ -495,7 +497,11 @@ public final class ItemStack {
nbt.putString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString());
nbt.putByte("Count", (byte) this.count);
if (this.tag != null) {
- nbt.put("tag", this.tag.copy());
+ // Scissors start - Don't save large tags
+ if (!NbtUtility.isTooLarge(this.tag)) {
+ nbt.put("tag", this.tag.copy());
+ }
+ // Scissors end
}
return nbt;
@@ -827,6 +833,9 @@ public final class ItemStack {
// Paper end
public void setTag(@Nullable CompoundTag nbt) {
+ // Scissors start - Ignore large tags
+ if (NbtUtility.isTooLarge(nbt)) return;
+ // Scissors end
this.tag = nbt;
this.processEnchantOrder(this.tag); // Paper
if (this.getItem().canBeDepleted()) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index 226d9ac01c601fc8954a88bea93a521cdce79eda..9bfa2deca1258dd9c294422a0ea032142cd11789 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -1,16 +1,12 @@
package org.bukkit.craftbukkit.inventory;
-import static org.bukkit.craftbukkit.inventory.CraftMetaItem.*;
import com.google.common.collect.ImmutableMap;
-import java.util.Map;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.item.Item;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
-import org.bukkit.NamespacedKey;
import org.bukkit.configuration.serialization.DelegateDeserialization;
-import org.bukkit.craftbukkit.enchantments.CraftEnchantment;
import org.bukkit.craftbukkit.util.CraftLegacy;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
@@ -19,6 +15,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.material.MaterialData;
+import java.util.Map;
+
+import static org.bukkit.craftbukkit.inventory.CraftMetaItem.ENCHANTMENTS_ID;
+import static org.bukkit.craftbukkit.inventory.CraftMetaItem.ENCHANTMENTS_LVL;
+
@DelegateDeserialization(ItemStack.class)
public final class CraftItemStack extends ItemStack {