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
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java b/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java
|
2023-06-16 19:27:59 +02:00
|
|
|
index 97da8896865ff0bdd4fe8f2155b0830b42051bb1..9ca897d92c5bdd2764d114c74d64c776674d6beb 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
|
2023-03-14 21:55:49 +01:00
|
|
|
@@ -42,7 +42,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
|
2023-06-08 09:20:03 +02:00
|
|
|
index 09f6948a52721b27ccd7c761a7efd09bfd7a183c..71a8812365503d840f6702a21d504a37d67c7194 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-06-08 09:20:03 +02:00
|
|
|
@@ -338,7 +338,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));
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2023-06-12 19:03:51 +02:00
|
|
|
index 70cdcc7508998ef1b107f60c619c3d521dadd124..3161b5da8bd4045123ee067ffc693165507a02ea 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
|
2023-06-12 19:03:51 +02:00
|
|
|
@@ -3167,7 +3167,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));
|
|
|
|
+ // Paper end
|
|
|
|
switch (enumitemslot.getType()) {
|
|
|
|
case HAND:
|
|
|
|
this.setLastHandItem(enumitemslot, itemstack1);
|
2023-06-12 19:03:51 +02:00
|
|
|
@@ -3180,6 +3183,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;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
private ItemStack getLastArmorItem(EquipmentSlot slot) {
|
|
|
|
return (ItemStack) this.lastArmorItemStacks.get(slot.getIndex());
|
|
|
|
}
|