From 32ba851514293c53351a4262d5b0b1d1051bcab6 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Wed, 8 May 2024 12:47:03 -0500 Subject: [PATCH] add more --- build-data/dev-imports.txt | 7 +- ...es-with-invalid-namespaces-from-bein.patch | 28 ++++ ...ery-player-data-in-the-nbt-component.patch | 39 +++++ ...string-tag-visitors-to-1024-elements.patch | 142 ++++++++++++++++++ ...illing-potion-effects-and-certain-po.patch | 34 +++++ 5 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 patches/server/0010-Prevent-attributes-with-invalid-namespaces-from-bein.patch create mode 100644 patches/server/0011-Don-t-query-player-data-in-the-nbt-component.patch create mode 100644 patches/server/0012-Limit-string-tag-visitors-to-1024-elements.patch create mode 100644 patches/server/0013-Fixes-creative-killing-potion-effects-and-certain-po.patch diff --git a/build-data/dev-imports.txt b/build-data/dev-imports.txt index 3509d64..6defb1a 100644 --- a/build-data/dev-imports.txt +++ b/build-data/dev-imports.txt @@ -12,4 +12,9 @@ minecraft net.minecraft.network.chat.FormattedText minecraft net.minecraft.network.chat.contents.TranslatableContents.java minecraft net.minecraft.network.chat.HoverEvent minecraft net.minecraft.world.item.KnowledgeBookItem -minecraft net.minecraft.network.chat.contents.NbtContents \ No newline at end of file +minecraft net.minecraft.network.chat.contents.NbtContents +minecraft net.minecraft.network.chat.contents.EntityDataSource +minecraft net.minecraft.network.chat.contents.DataSource +minecraft net.minecraft.nbt.SnbtPrinterTagVisitor +minecraft net.minecraft.nbt.StringTagVisitor +minecraft net.minecraft.nbt.TextComponentTagVisitor \ No newline at end of file diff --git a/patches/server/0010-Prevent-attributes-with-invalid-namespaces-from-bein.patch b/patches/server/0010-Prevent-attributes-with-invalid-namespaces-from-bein.patch new file mode 100644 index 0000000..88c2b85 --- /dev/null +++ b/patches/server/0010-Prevent-attributes-with-invalid-namespaces-from-bein.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Wed, 8 May 2024 12:26:49 -0500 +Subject: [PATCH] Prevent attributes with invalid namespaces from being applied + to CraftMetaItems + + +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +index ab23597a099a2785c803e08c93ff9f046a4af677..8fa0557cbf17fee958da9bd8d09a51748282a980 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +@@ -50,6 +50,7 @@ import net.minecraft.nbt.NbtIo; + import net.minecraft.nbt.NbtOps; + import net.minecraft.nbt.Tag; + import net.minecraft.network.chat.Component; ++import net.minecraft.resources.ResourceLocation; + import net.minecraft.server.MinecraftServer; + import net.minecraft.util.Unit; + import net.minecraft.world.entity.EquipmentSlotGroup; +@@ -734,7 +735,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { + continue; + } + String attributeName = (String) obj; +- if (Strings.isNullOrEmpty(attributeName)) { ++ if (Strings.isNullOrEmpty(attributeName) || attributeName.length() > 256 || !ResourceLocation.isValidResourceLocation(attributeName)) { // Scissors + continue; + } + List list = SerializableMeta.getObject(List.class, mods, attributeName, true); diff --git a/patches/server/0011-Don-t-query-player-data-in-the-nbt-component.patch b/patches/server/0011-Don-t-query-player-data-in-the-nbt-component.patch new file mode 100644 index 0000000..4c1db91 --- /dev/null +++ b/patches/server/0011-Don-t-query-player-data-in-the-nbt-component.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Wed, 8 May 2024 12:35:56 -0500 +Subject: [PATCH] Don't query player data in the `nbt` component + + +diff --git a/src/main/java/net/minecraft/network/chat/contents/EntityDataSource.java b/src/main/java/net/minecraft/network/chat/contents/EntityDataSource.java +index 2750702cff35762bc817ffbe5bf81631e86bc49b..f69261dae717cbb3e7bc9f5e0767adc897f0388d 100644 +--- a/src/main/java/net/minecraft/network/chat/contents/EntityDataSource.java ++++ b/src/main/java/net/minecraft/network/chat/contents/EntityDataSource.java +@@ -8,12 +8,15 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; + import java.util.List; + import java.util.stream.Stream; + import javax.annotation.Nullable; ++ ++import me.totalfreedom.scissors.ScissorsConfig; + import net.minecraft.advancements.critereon.NbtPredicate; + import net.minecraft.commands.CommandSourceStack; + import net.minecraft.commands.arguments.selector.EntitySelector; + import net.minecraft.commands.arguments.selector.EntitySelectorParser; + import net.minecraft.nbt.CompoundTag; + import net.minecraft.world.entity.Entity; ++import org.bukkit.entity.Player; + + public record EntityDataSource(String selectorPattern, @Nullable EntitySelector compiledSelector) implements DataSource { + public static final MapCodec SUB_CODEC = RecordCodecBuilder.mapCodec( +@@ -39,7 +42,11 @@ public record EntityDataSource(String selectorPattern, @Nullable EntitySelector + public Stream getData(CommandSourceStack source) throws CommandSyntaxException { + if (this.compiledSelector != null) { + List list = this.compiledSelector.findEntities(source); +- return list.stream().map(NbtPredicate::getEntityTagToCompare); ++ // Scissors start ++ Stream stream = list.stream(); ++ if (ScissorsConfig.excludePlayersFromNbtComponents) stream = stream.filter((entity) -> !(entity instanceof Player)); ++ return stream.map(NbtPredicate::getEntityTagToCompare); ++ // Scissors end + } else { + return Stream.empty(); + } diff --git a/patches/server/0012-Limit-string-tag-visitors-to-1024-elements.patch b/patches/server/0012-Limit-string-tag-visitors-to-1024-elements.patch new file mode 100644 index 0000000..f723ae2 --- /dev/null +++ b/patches/server/0012-Limit-string-tag-visitors-to-1024-elements.patch @@ -0,0 +1,142 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Wed, 8 May 2024 12:43:35 -0500 +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 b45bb4ddf6b586ba1285db230e0bc3d1b5e447e8..4a46935cac263325a87a1b0bf32302839a75516e 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(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 d8892641d5671fa100aeb43d42ebb6103a2d280c..d10242ecd6f8442e1af3f4cd13f769517b33058a 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 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 6644359d68706b7c3af2f782c33f930387c221d7..b76cd0ff6f60d83da8754ef788bc0e669b8b4f9c 100644 +--- a/src/main/java/net/minecraft/nbt/TextComponentTagVisitor.java ++++ b/src/main/java/net/minecraft/nbt/TextComponentTagVisitor.java +@@ -105,6 +105,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(bs[i])).withStyle(SYNTAX_HIGHLIGHTING_NUMBER); +@@ -123,6 +124,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)); +@@ -140,6 +142,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); +@@ -155,7 +158,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 (this.depth >= 64) { + this.result = Component.literal("[").append(TOO_DEEP).append("]"); +@@ -202,7 +205,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 if (this.depth >= 64) { + this.result = Component.literal("{").append(TOO_DEEP).append("}"); diff --git a/patches/server/0013-Fixes-creative-killing-potion-effects-and-certain-po.patch b/patches/server/0013-Fixes-creative-killing-potion-effects-and-certain-po.patch new file mode 100644 index 0000000..4531674 --- /dev/null +++ b/patches/server/0013-Fixes-creative-killing-potion-effects-and-certain-po.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Wed, 8 May 2024 12:46:29 -0500 +Subject: [PATCH] Fixes creative-killing potion effects and certain potion + effect overflows + + +diff --git a/src/main/java/net/minecraft/world/effect/HealOrHarmMobEffect.java b/src/main/java/net/minecraft/world/effect/HealOrHarmMobEffect.java +index b95afa9f6b7cf6c522ff5ec278adec7a9a851e9a..3f65f24936cdf3379e39bab3cd8bd46aacd95518 100644 +--- a/src/main/java/net/minecraft/world/effect/HealOrHarmMobEffect.java ++++ b/src/main/java/net/minecraft/world/effect/HealOrHarmMobEffect.java +@@ -15,6 +15,10 @@ class HealOrHarmMobEffect extends InstantenousMobEffect { + + @Override + public boolean applyEffectTick(LivingEntity entity, int amplifier) { ++ // Scissors start - Don't apply any healing/harming effects for Creative/Invulnerable players and cap the amplifier for those who aren't. ++ if (entity instanceof net.minecraft.world.entity.player.Player player && (player.isCreative() || player.isInvulnerable())) return false; ++ amplifier = Math.min(Math.abs(amplifier), 124); ++ // Scissors end + if (this.isHarm == entity.isInvertedHealAndHarm()) { + entity.heal((float) Math.max(4 << amplifier, 0), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.MAGIC); // CraftBukkit + } else { +@@ -28,6 +32,11 @@ class HealOrHarmMobEffect extends InstantenousMobEffect { + public void applyInstantenousEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) { + int j; + ++ // Scissors start - Don't apply any healing/harming effects for Creative/Invulnerable players and cap the amplifier for those who aren't. ++ if (target instanceof net.minecraft.world.entity.player.Player player && (player.isCreative() || player.isInvulnerable())) return; ++ amplifier = Math.min(Math.abs(amplifier), 124); ++ // Scissors end ++ + if (this.isHarm == target.isInvertedHealAndHarm()) { + j = (int) (proximity * (double) (4 << amplifier) + 0.5D); + target.heal((float) j, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.MAGIC); // CraftBukkit