From cb591a98f4da00a80bc4a288ddd1d8b3b15f4f34 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Jan 2019 21:50:43 +0000 Subject: [PATCH] NetworkBinaryStream: Skip item NBT which is too large when encoded Encoded tags larger than 32KB overflow the length field, so we can't send these over network. However, it's unreasonable to randomly throw this burden off onto users by crashing their servers, so the next best solution is to just not send the NBT. This is also not an ideal solution (books and the like with too-large tags won't work on the client side) but it's better than crashing the server or client due to a protocol bug. Mojang have confirmed this will be resolved by a future MCPE release, so we'll just work around this problem until then. --- src/pocketmine/network/mcpe/NetworkBinaryStream.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 95800942a..3271bea7e 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -113,7 +113,17 @@ class NetworkBinaryStream extends BinaryStream{ $nbt = $item->getCompoundTag(); $nbtLen = strlen($nbt); if($nbtLen > 32767){ - throw new \InvalidArgumentException("NBT encoded length must be < 32768, got $nbtLen bytes"); + /* + * TODO: Workaround bug in the protocol (overflow) + * Encoded tags larger than 32KB overflow the length field, so we can't send these over network. + * However, it's unreasonable to randomly throw this burden off onto users by crashing their servers, so the + * next best solution is to just not send the NBT. This is also not an ideal solution (books and the like + * with too-large tags won't work on the client side) but it's better than crashing the server or client due + * to a protocol bug. Mojang have confirmed this will be resolved by a future MCPE release, so we'll just + * work around this problem until then. + */ + $nbt = ""; + $nbtLen = 0; } $this->putLShort($nbtLen);