2021-12-01 13:32:36 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2022-08-01 16:01:20 +02:00
|
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
2021-12-01 13:32:36 +01:00
|
|
|
Date: Wed, 1 Dec 2021 12:36:25 +0100
|
|
|
|
Subject: [PATCH] Prevent sending oversized item data in equipment and metadata
|
|
|
|
|
2024-04-24 18:15:59 +02:00
|
|
|
TODO: Check if still needed with compacted items over the network and limits
|
|
|
|
|
2021-12-01 13:32:36 +01:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java b/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java
|
2024-04-12 21:14:06 +02:00
|
|
|
index 3ee4c01e4505241e575b8b2e96338ba27b793a2b..d70f77e4d5ca59c9f802ecb354fa8d53d1e10134 100644
|
2021-12-01 13:32:36 +01:00
|
|
|
--- a/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -44,7 +44,7 @@ public class EntityDataSerializers {
|
2021-12-01 13:32:36 +01:00
|
|
|
public static final EntityDataSerializer<ItemStack> ITEM_STACK = new EntityDataSerializer<ItemStack>() {
|
|
|
|
@Override
|
|
|
|
public void write(FriendlyByteBuf buf, ItemStack value) {
|
|
|
|
- buf.writeItem(value);
|
2023-06-16 19:27:59 +02:00
|
|
|
+ buf.writeItem(net.minecraft.world.entity.LivingEntity.sanitizeItemStack(value, true)); // Paper - prevent oversized data
|
2021-12-01 13:32:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
2024-04-12 21:14:06 +02:00
|
|
|
index 91563f903834c1a0636dc087f8c6376815165b6c..a51564e8dce3c125ed5f05cc23548a05c1e79a95 100644
|
2021-12-01 13:32:36 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
2023-09-22 16:58:35 +02:00
|
|
|
@@ -335,7 +335,10 @@ public class ServerEntity {
|
2021-12-01 13:32:36 +01:00
|
|
|
ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(enumitemslot);
|
|
|
|
|
|
|
|
if (!itemstack.isEmpty()) {
|
|
|
|
- list.add(Pair.of(enumitemslot, itemstack.copy()));
|
|
|
|
+ // Paper start - prevent oversized data
|
|
|
|
+ final ItemStack sanitized = LivingEntity.sanitizeItemStack(itemstack.copy(), false);
|
|
|
|
+ list.add(Pair.of(enumitemslot, sanitized));
|
2024-01-18 22:00:40 +01:00
|
|
|
+ // Paper end - prevent oversized data
|
2021-12-01 13:32:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-04-12 21:14:06 +02:00
|
|
|
index ed6fd20ff608e764d6b0f517f6c9c85c533f1646..8025e351fb3e24aa67b31eca74be1bc368592851 100644
|
2021-12-01 13:32:36 +01:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -3208,7 +3208,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2021-12-01 13:32:36 +01:00
|
|
|
equipmentChanges.forEach((enumitemslot, itemstack) -> {
|
|
|
|
ItemStack itemstack1 = itemstack.copy();
|
|
|
|
|
|
|
|
- list.add(Pair.of(enumitemslot, itemstack1));
|
|
|
|
+ // Paper start - prevent oversized data
|
|
|
|
+ ItemStack toSend = sanitizeItemStack(itemstack1, true);
|
|
|
|
+ list.add(Pair.of(enumitemslot, toSend));
|
2024-01-18 22:00:40 +01:00
|
|
|
+ // Paper end - prevent oversized data
|
2021-12-01 13:32:36 +01:00
|
|
|
switch (enumitemslot.getType()) {
|
|
|
|
case HAND:
|
|
|
|
this.setLastHandItem(enumitemslot, itemstack1);
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -3221,6 +3224,34 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2023-06-08 09:20:03 +02:00
|
|
|
((ServerLevel) this.level()).getChunkSource().broadcast(this, new ClientboundSetEquipmentPacket(this.getId(), list));
|
2021-12-01 13:32:36 +01:00
|
|
|
}
|
|
|
|
|
2022-01-02 00:26:53 +01:00
|
|
|
+ // Paper start - prevent oversized data
|
2021-12-01 13:32:36 +01:00
|
|
|
+ public static ItemStack sanitizeItemStack(final ItemStack itemStack, final boolean copyItemStack) {
|
|
|
|
+ if (itemStack.isEmpty() || !itemStack.hasTag()) {
|
|
|
|
+ return itemStack;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final ItemStack copy = copyItemStack ? itemStack.copy() : itemStack;
|
|
|
|
+ final CompoundTag tag = copy.getTag();
|
|
|
|
+ if (copy.is(Items.BUNDLE) && tag.get("Items") instanceof ListTag oldItems && !oldItems.isEmpty()) {
|
|
|
|
+ // Bundles change their texture based on their fullness.
|
|
|
|
+ org.bukkit.inventory.meta.BundleMeta bundleMeta = (org.bukkit.inventory.meta.BundleMeta) copy.asBukkitMirror().getItemMeta();
|
|
|
|
+ int sizeUsed = 0;
|
|
|
|
+ for (org.bukkit.inventory.ItemStack item : bundleMeta.getItems()) {
|
|
|
|
+ int scale = 64 / item.getMaxStackSize();
|
|
|
|
+ sizeUsed += scale * item.getAmount();
|
|
|
|
+ }
|
|
|
|
+ // Now we add a single fake item that uses the same amount of slots as all other items.
|
|
|
|
+ ListTag items = new ListTag();
|
|
|
|
+ items.add(new ItemStack(Items.PAPER, sizeUsed).save(new CompoundTag()));
|
|
|
|
+ tag.put("Items", items);
|
|
|
|
+ }
|
|
|
|
+ if (tag.get("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
|
|
|
+ blockEntityTag.remove("Items");
|
|
|
|
+ }
|
|
|
|
+ return copy;
|
|
|
|
+ }
|
2024-01-18 22:00:40 +01:00
|
|
|
+ // Paper end - prevent oversized data
|
2021-12-01 13:32:36 +01:00
|
|
|
+
|
|
|
|
private ItemStack getLastArmorItem(EquipmentSlot slot) {
|
|
|
|
return (ItemStack) this.lastArmorItemStacks.get(slot.getIndex());
|
|
|
|
}
|