Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
e035fd7034
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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
87 Zeilen
4.7 KiB
Diff
87 Zeilen
4.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
|
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
|
|
index f9e15908143f4453c2a5817b412e8a13554553f0..06498788c169133bd563c5a87192b71802c4d4df 100644
|
|
--- a/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java
|
|
+++ b/src/main/java/net/minecraft/network/syncher/EntityDataSerializers.java
|
|
@@ -42,7 +42,7 @@ public class EntityDataSerializers {
|
|
public static final EntityDataSerializer<ItemStack> ITEM_STACK = new EntityDataSerializer<ItemStack>() {
|
|
@Override
|
|
public void write(FriendlyByteBuf buf, ItemStack value) {
|
|
- buf.writeItem(value);
|
|
+ buf.writeItem(net.minecraft.world.entity.LivingEntity.sanitizeItemStack(value, true)); // Paper - prevent oversized data
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index e0802f1cb73a80b08482832c2b269ac8485d5c1a..8d2870c780c4c253f6570c7ef73f6e7c2ccc46ad 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -335,7 +335,10 @@ public class ServerEntity {
|
|
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
|
|
index ffc999a3a398bc73fffa7a68805baa1da7504750..3de3e938195c79c65b7e11438ca92585aaccf529 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -3188,7 +3188,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
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);
|
|
@@ -3201,6 +3204,34 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
((ServerLevel) this.level()).getChunkSource().broadcast(this, new ClientboundSetEquipmentPacket(this.getId(), list));
|
|
}
|
|
|
|
+ // Paper start - prevent oversized data
|
|
+ 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());
|
|
}
|