Scissors/patches/server/0004-ResourceLocation-validation.patch

124 lines
7.2 KiB
Diff
Raw Normal View History

2023-09-24 20:29:45 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2024-02-13 21:52:00 +00:00
From: Video <videogamesm12@gmail.com>
2024-01-24 22:30:21 +00:00
Date: Wed, 24 Jan 2024 16:28:16 -0600
2023-09-24 20:29:45 +00:00
Subject: [PATCH] ResourceLocation validation
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
index 15173e715fa36546820d930a46e0f0c493d07cfc..356cc6f468975faa676db87db8fc0fa2df32f020 100644
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
@@ -17,7 +17,7 @@ public class PaperContainerEntityLootableInventory implements PaperLootableEntit
@Override
public org.bukkit.loot.LootTable getLootTable() {
- return entity.getLootTable() != null && !entity.getLootTable().getPath().isEmpty() ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(entity.getLootTable())) : null;
+ return entity.getLootTable() != null && !entity.getLootTable().getPath().isEmpty() && entity.getLootTable().toString().length() < 256 ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(entity.getLootTable())) : null; // Scissors - Validate length of loot tables before even trying
}
@Override
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
index 2ee4ee14ab3345486dad6b24fd9a4fcc6c746b99..c5ac6cda91a81d3075f5c763e30dc009b6be7936 100644
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
@@ -15,7 +15,7 @@ public class PaperTileEntityLootableInventory implements PaperLootableBlockInven
@Override
public org.bukkit.loot.LootTable getLootTable() {
- return tileEntityLootable.lootTable != null && !tileEntityLootable.lootTable.getPath().isEmpty() ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(tileEntityLootable.lootTable)) : null;
+ return tileEntityLootable.lootTable != null && !tileEntityLootable.lootTable.getPath().isEmpty() && tileEntityLootable.lootTable.toString().length() < 256 ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(tileEntityLootable.lootTable)) : null; // Scissors - Validate length of loot tables before even trying
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
2024-02-24 22:32:31 +00:00
index 094ab43e5a209ea848bf0994db9018281c64e08d..c6faba7da6809e24d734b7d6b0b787d20163b051 100644
2023-09-24 20:29:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
+++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
2024-02-24 22:32:31 +00:00
@@ -410,7 +410,7 @@ public class AreaEffectCloud extends Entity implements TraceableEntity {
2023-09-24 20:29:45 +00:00
try {
this.setParticle(ParticleArgument.readParticle(new StringReader(nbt.getString("Particle")), (HolderLookup) BuiltInRegistries.PARTICLE_TYPE.asLookup()));
} 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/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 09e8445a3f8c6b3ebc852a75a9a25b41a51ba659..cfb2ce684da0ae97a844554b5ad3d41290058f32 100644
2023-09-24 20:29:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -595,7 +595,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
2024-01-18 23:05:55 +00:00
if (generation) entity.generation = true; // Paper - Don't fire sync event during generation
2023-09-24 20:29:45 +00:00
entity.load(nbt);
}, () -> {
- EntityType.LOGGER.warn("Skipping Entity with id {}", nbt.getString("id"));
+ // Scissors - Don't log invalid entities
});
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
2023-10-29 20:36:20 +00:00
index f6942cb3ef1f9ef03708d4bc932ea9aeb1c13894..8b32864bafb3c1948993688be8f639dd6492057e 100644
2023-09-24 20:29:45 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
@@ -34,8 +34,14 @@ public abstract class CraftLootable<T extends RandomizableContainerBlockEntity>
2023-09-24 20:29:45 +00:00
return null;
}
2023-10-29 20:36:20 +00:00
- ResourceLocation key = this.getSnapshot().lootTable;
2023-09-24 20:29:45 +00:00
- return Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(key));
+ // Scissors start - Return a null loot table if the specified loot table is not valid
+ try {
2023-10-29 20:36:20 +00:00
+ ResourceLocation key = this.getSnapshot().lootTable;
2023-09-24 20:29:45 +00:00
+ 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
2023-12-10 19:43:18 +00:00
index 313ee5c8737b2e57f9b5db6512c1871766b2ccd4..a115a13ec911884a804800fc13f0347be1a30932 100644
2023-09-24 20:29:45 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
2023-12-10 19:43:18 +00:00
@@ -33,8 +33,15 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo
2023-09-24 20:29:45 +00:00
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
2023-12-10 19:43:18 +00:00
+ try
+ {
2023-09-24 20:29:45 +00:00
+ NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable);
+ return Bukkit.getLootTable(key);
2023-12-10 19:43:18 +00:00
+ } catch (Exception exception) {
2023-09-24 20:29:45 +00:00
+ 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
2024-01-24 22:30:21 +00:00
index 31f62fbb54ec7b270fbd8afba7bd7c4bfafa09e3..684e69753be0398ebe57172454aba8cc45cf6502 100644
2023-09-24 20:29:45 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
2023-12-10 19:43:18 +00:00
@@ -80,8 +80,15 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
2023-09-24 20:29:45 +00:00
@Override
public LootTable getLootTable() {
- NamespacedKey key = CraftNamespacedKey.fromMinecraft(this.getHandle().getLootTable());
- return Bukkit.getLootTable(key);
+ // Scissors start - Return a null loot table if the specified loot table is not valid
2023-12-10 19:43:18 +00:00
+ try
+ {
2023-09-24 20:29:45 +00:00
+ NamespacedKey key = CraftNamespacedKey.fromMinecraft(this.getHandle().getLootTable());
+ return Bukkit.getLootTable(key);
+ } catch (Exception ex) {
+ return null;
+ }
+ // Scissors end
}
@Override