From aa48ad0b21548588d69cd671467738df5fd311a7 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Fri, 10 Jun 2022 23:55:22 -0500 Subject: [PATCH] Checkpoint --- ...ceLocation-validation-and-log-spam-f.patch | 86 +++++++++++++++++++ ...id-items-in-HoverEvent-and-ItemFrame.patch | 41 +++++++++ ...en-more-resource-location-validation.patch | 54 ++++++++++++ .../0015-Change-version-fetcher-to-AMG.patch | 73 ++++++++++++++++ ...es-with-invalid-namespaces-from-bein.patch | 28 ++++++ 5 files changed, 282 insertions(+) create mode 100644 patches/server/0012-Even-more-ResourceLocation-validation-and-log-spam-f.patch create mode 100644 patches/server/0013-Do-not-log-invalid-items-in-HoverEvent-and-ItemFrame.patch create mode 100644 patches/server/0014-Even-more-resource-location-validation.patch create mode 100644 patches/server/0015-Change-version-fetcher-to-AMG.patch create mode 100644 patches/server/0016-Prevent-attributes-with-invalid-namespaces-from-bein.patch diff --git a/patches/server/0012-Even-more-ResourceLocation-validation-and-log-spam-f.patch b/patches/server/0012-Even-more-ResourceLocation-validation-and-log-spam-f.patch new file mode 100644 index 0000000..295afa7 --- /dev/null +++ b/patches/server/0012-Even-more-ResourceLocation-validation-and-log-spam-f.patch @@ -0,0 +1,86 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Mon, 9 May 2022 23:40:59 -0500 +Subject: [PATCH] Even more ResourceLocation validation and log spam fixes + + +diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java +index 7e1885d9cc568a544e934cede32bff05c20b567a..2481c50d8eb58a003e30e2d957b877bce5123a3a 100644 +--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java ++++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java +@@ -420,7 +420,7 @@ public class AreaEffectCloud extends Entity { + try { + this.setParticle(ParticleArgument.readParticle(new StringReader(nbt.getString("Particle")))); + } catch (CommandSyntaxException commandsyntaxexception) { +- AreaEffectCloud.LOGGER.warn("Couldn't load custom particle {}", nbt.getString("Particle"), commandsyntaxexception); ++ // Scissors - Don't log custom particle errors + } + } + +diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java +index e49eece9bff3a53469673d03a7bbf8f9cf8776b8..a49f32e9649155b6af4b1f236e4e8142d730e7e8 100644 +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java +@@ -30,8 +30,14 @@ public abstract class CraftLootable + return null; + } + +- ResourceLocation key = getSnapshot().lootTable; +- return Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(key)); ++ // Scissors start - Return a null loot table if the specified loot table is not valid ++ try { ++ ResourceLocation key = getSnapshot().lootTable; ++ return Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(key)); ++ } catch (Exception ex) { ++ return null; ++ } ++ // Scissors end + } + + @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java +index 0dd0ce9a9b3253e87eda12354249ec2fd2a33cf2..b6920f9432ca1736afbe775186fbbcf11cf046fb 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java +@@ -33,8 +33,14 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo + return null; // return empty loot table? + } + +- NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable); +- return Bukkit.getLootTable(key); ++ // Scissors start - Return a null loot table if the specified loot table is not valid ++ try { ++ NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable); ++ return Bukkit.getLootTable(key); ++ } catch (Exception ex) { ++ return null; ++ } ++ // Scissors end + } + + @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java +index d775e19402188e35f79affb4ed636b6533f90ab5..29f5ab80ffbc421da911046678427755c6156894 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java +@@ -63,8 +63,18 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob { + + @Override + public LootTable getLootTable() { +- NamespacedKey key = CraftNamespacedKey.fromMinecraft(this.getHandle().getLootTable()); +- return Bukkit.getLootTable(key); ++ if (this.getHandle().lootTable == null) { ++ this.getHandle().lootTable = this.getHandle().getDefaultLootTable(); ++ } ++ ++ // Scissors start - Return a null loot table if the specified loot table is not valid ++ try { ++ NamespacedKey key = CraftNamespacedKey.fromMinecraft(this.getHandle().getLootTable()); ++ return Bukkit.getLootTable(key); ++ } catch (Exception ex) { ++ return null; ++ } ++ // Scissors end + } + + @Override diff --git a/patches/server/0013-Do-not-log-invalid-items-in-HoverEvent-and-ItemFrame.patch b/patches/server/0013-Do-not-log-invalid-items-in-HoverEvent-and-ItemFrame.patch new file mode 100644 index 0000000..a6ab198 --- /dev/null +++ b/patches/server/0013-Do-not-log-invalid-items-in-HoverEvent-and-ItemFrame.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Luna +Date: Sun, 20 Mar 2022 09:31:16 -0300 +Subject: [PATCH] Do not log invalid items in HoverEvent and ItemFrame + + +diff --git a/src/main/java/net/minecraft/network/chat/HoverEvent.java b/src/main/java/net/minecraft/network/chat/HoverEvent.java +index b50cd7a39c077dcbabdfea1b9290bf5b144d4384..d38562b518b28ba4617d39e4587c7fa72859ab11 100644 +--- a/src/main/java/net/minecraft/network/chat/HoverEvent.java ++++ b/src/main/java/net/minecraft/network/chat/HoverEvent.java +@@ -314,7 +314,7 @@ public class HoverEvent { + CompoundTag compoundTag = TagParser.parseTag(string); + return new HoverEvent.ItemStackInfo(item, i, compoundTag); + } catch (CommandSyntaxException var6) { +- HoverEvent.LOGGER.warn("Failed to parse tag: {}", string, var6); ++ // Scissors - Ignore invalid items + } + } + +@@ -328,7 +328,7 @@ public class HoverEvent { + CompoundTag compoundTag = TagParser.parseTag(text.getString()); + return new HoverEvent.ItemStackInfo(ItemStack.of(compoundTag)); + } catch (CommandSyntaxException var2) { +- HoverEvent.LOGGER.warn("Failed to parse item tag: {}", text, var2); ++ // Scissors - Ignore invalid items + return null; + } + } +diff --git a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java +index d2a77b4ca343d19e1c70afe3f3906a9bd53d0eec..93de0f1376604ad3f2c519c04f12269484dabfe9 100644 +--- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java ++++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java +@@ -420,7 +420,7 @@ public class ItemFrame extends HangingEntity { + ItemStack itemstack = ItemStack.of(nbttagcompound1); + + if (itemstack.isEmpty()) { +- ItemFrame.LOGGER.warn("Unable to load item from: {}", nbttagcompound1); ++ // Scissors - ignore invalid items + } + + ItemStack itemstack1 = this.getItem(); diff --git a/patches/server/0014-Even-more-resource-location-validation.patch b/patches/server/0014-Even-more-resource-location-validation.patch new file mode 100644 index 0000000..320f2ae --- /dev/null +++ b/patches/server/0014-Even-more-resource-location-validation.patch @@ -0,0 +1,54 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Fri, 22 Apr 2022 01:19:49 -0500 +Subject: [PATCH] Even more resource location validation + + +diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java +index 2481c50d8eb58a003e30e2d957b877bce5123a3a..6b284666eae8b7e0ef8f54dfe9311a0979b420fe 100644 +--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java ++++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java +@@ -143,7 +143,7 @@ public class AreaEffectCloud extends Entity { + } + + public void setPotionType(String string) { +- this.setPotion(Registry.POTION.get(new ResourceLocation(string))); ++ this.setPotion(Registry.POTION.get(ResourceLocation.tryParse(string))); // Scissors - Validate resource locations + } + // CraftBukkit end + +diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java +index ac0f0a4da4282c13f6e1f37710cb615d66b8ef2c..e789bcb0c426651a48fb3c78e885c6e3fafb0416 100644 +--- a/src/main/java/net/minecraft/world/entity/EntityType.java ++++ b/src/main/java/net/minecraft/world/entity/EntityType.java +@@ -518,7 +518,7 @@ public class EntityType implements EntityTypeTest { + }), (entity) -> { + entity.load(nbt); + }, () -> { +- EntityType.LOGGER.warn("Skipping Entity with id {}", nbt.getString("id")); ++ // Scissors - Don't log invalid entities + }); + } + +@@ -537,7 +537,7 @@ public class EntityType implements EntityTypeTest { + } + + public static Optional> by(CompoundTag nbt) { +- return Registry.ENTITY_TYPE.getOptional(new ResourceLocation(nbt.getString("id"))); ++ return Registry.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(nbt.getString("id"))); // Scissors - Validate resource locations + } + + @Nullable +diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java +index 3646b969fa51b9683ab4137e530c3a6f6fc6c465..286e9a8d3673be3a7fef2af6402e025d3058f6e7 100644 +--- a/src/main/java/net/minecraft/world/entity/Mob.java ++++ b/src/main/java/net/minecraft/world/entity/Mob.java +@@ -579,7 +579,7 @@ public abstract class Mob extends LivingEntity { + + this.setLeftHanded(nbt.getBoolean("LeftHanded")); + if (nbt.contains("DeathLootTable", 8)) { +- this.lootTable = new ResourceLocation(nbt.getString("DeathLootTable")); ++ this.lootTable = ResourceLocation.tryParse(nbt.getString("DeathLootTable")); // Scissors - Validate resource locations + this.lootTableSeed = nbt.getLong("DeathLootTableSeed"); + } + diff --git a/patches/server/0015-Change-version-fetcher-to-AMG.patch b/patches/server/0015-Change-version-fetcher-to-AMG.patch new file mode 100644 index 0000000..223b673 --- /dev/null +++ b/patches/server/0015-Change-version-fetcher-to-AMG.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Sat, 26 Mar 2022 21:51:07 -0500 +Subject: [PATCH] Change version fetcher to AMG + + +diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java +index bf42969859545a8a520923ef1836ffa4a5cc24a0..05be595d3e451bfbc5471fb3fb44dc704b83f4ac 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java ++++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java +@@ -4,6 +4,8 @@ import com.destroystokyo.paper.util.VersionFetcher; + import com.google.common.base.Charsets; + import com.google.common.io.Resources; + import com.google.gson.*; ++import io.papermc.paper.util.JarManifests; ++import java.util.Map; + import net.kyori.adventure.text.Component; + import net.kyori.adventure.text.event.ClickEvent; + import net.kyori.adventure.text.format.NamedTextColor; +@@ -19,8 +21,8 @@ import java.util.stream.StreamSupport; + + public class PaperVersionFetcher implements VersionFetcher { + private static final java.util.regex.Pattern VER_PATTERN = java.util.regex.Pattern.compile("^([0-9\\.]*)\\-.*R"); // R is an anchor, will always give '-R' at end +- private static final String GITHUB_BRANCH_NAME = "master"; +- private static final String DOWNLOAD_PAGE = "https://papermc.io/downloads"; ++ private static final String GITHUB_BRANCH_NAME = getBranch(); ++ private static final String DOWNLOAD_PAGE = "https://ci.plex.us.org/job/Scissors/job/" + GITHUB_BRANCH_NAME; + private static @Nullable String mcVer; + + @Override +@@ -31,8 +33,8 @@ public class PaperVersionFetcher implements VersionFetcher { + @Nonnull + @Override + public Component getVersionMessage(@Nonnull String serverVersion) { +- String[] parts = serverVersion.substring("git-Paper-".length()).split("[-\\s]"); +- final Component updateMessage = getUpdateStatusMessage("PaperMC/Paper", GITHUB_BRANCH_NAME, parts[0]); ++ String[] parts = serverVersion.substring("git-Scissors-".length()).split("[-\\s]"); ++ final Component updateMessage = getUpdateStatusMessage("AtlasMediaGroup/Scissors", GITHUB_BRANCH_NAME, parts[0]); + final Component history = getHistory(); + + return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage; +@@ -54,15 +56,24 @@ public class PaperVersionFetcher implements VersionFetcher { + return mcVer; + } + ++ // Scissors start - Allow getting git information ++ public static String getCommit() { ++ Map attributes = JarManifests.MANIFEST_MAP; ++ return attributes.get("Git-Commit"); ++ } ++ ++ public static String getBranch() { ++ Map attributes = JarManifests.MANIFEST_MAP; ++ return attributes.get("Git-Branch"); ++ } ++ // Scissors end ++ + private static Component getUpdateStatusMessage(@Nonnull String repo, @Nonnull String branch, @Nonnull String versionInfo) { + int distance; +- try { +- int jenkinsBuild = Integer.parseInt(versionInfo); +- distance = fetchDistanceFromSiteApi(jenkinsBuild, getMinecraftVersion()); +- } catch (NumberFormatException ignored) { +- versionInfo = versionInfo.replace("\"", ""); +- distance = fetchDistanceFromGitHub(repo, branch, versionInfo); +- } ++ // Scissors start - always use Git for version checking ++ versionInfo = getCommit(); ++ distance = fetchDistanceFromGitHub(repo, branch, versionInfo); ++ // Scissors end + + switch (distance) { + case -1: diff --git a/patches/server/0016-Prevent-attributes-with-invalid-namespaces-from-bein.patch b/patches/server/0016-Prevent-attributes-with-invalid-namespaces-from-bein.patch new file mode 100644 index 0000000..8050c1c --- /dev/null +++ b/patches/server/0016-Prevent-attributes-with-invalid-namespaces-from-bein.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Video +Date: Wed, 30 Mar 2022 18:20:09 -0600 +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 d8eb84f28761dce95330afc32e4c011a4ab89b18..8644536d6f1be27d49a7260f35b776ba91144f07 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +@@ -46,6 +46,7 @@ import net.minecraft.nbt.NbtIo; + import net.minecraft.nbt.StringTag; + import net.minecraft.nbt.Tag; + import net.minecraft.network.chat.Component; ++import net.minecraft.resources.ResourceLocation; + import net.minecraft.world.item.BlockItem; + import org.apache.commons.lang.Validate; + import org.apache.commons.lang3.EnumUtils; +@@ -481,7 +482,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { + AttributeModifier attribMod = CraftAttributeInstance.convert(nmsModifier); + + String attributeName = CraftAttributeMap.convertIfNeeded(entry.getString(ATTRIBUTES_IDENTIFIER.NBT)); // Paper +- if (attributeName == null || attributeName.isEmpty()) { ++ if (attributeName == null || attributeName.isEmpty() || attributeName.length() < 256 || !ResourceLocation.isValidResourceLocation(attributeName)) { // Scissors + continue; + } +