From 0c250a2ef09627b48aa52302f6cc7e1f2afb70ea Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 11 Jul 2023 12:53:29 +0100 Subject: [PATCH] InGamePacketHandler: fixed inconsistent handling of invalid data in BlockActorDataPacket --- .../mcpe/handler/InGamePacketHandler.php | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 329bcd6ef..3ea3e0ad9 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -113,9 +113,9 @@ use pocketmine\utils\TextFormat; use pocketmine\utils\Utils; use pocketmine\world\format\Chunk; use function array_push; -use function base64_encode; use function count; use function fmod; +use function get_debug_type; use function implode; use function in_array; use function is_bool; @@ -748,27 +748,32 @@ class InGamePacketHandler extends PacketHandler{ if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit if($block instanceof BaseSign){ - if(($textBlobTag = $nbt->getCompoundTag(Sign::TAG_FRONT_TEXT)?->getTag(Sign::TAG_TEXT_BLOB)) instanceof StringTag){ - try{ - $text = SignText::fromBlob($textBlobTag->getValue()); - }catch(\InvalidArgumentException $e){ - throw PacketHandlingException::wrap($e, "Invalid sign text update"); - } - - try{ - if(!$block->updateText($this->player, $text)){ - foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){ - $this->session->sendDataPacket($updatePacket); - } - } - }catch(\UnexpectedValueException $e){ - throw PacketHandlingException::wrap($e); - } - - return true; + $frontTextTag = $nbt->getTag(Sign::TAG_FRONT_TEXT); + if(!$frontTextTag instanceof CompoundTag){ + throw new PacketHandlingException("Invalid tag type " . get_debug_type($frontTextTag) . " for tag \"" . Sign::TAG_FRONT_TEXT . "\" in sign update data"); + } + $textBlobTag = $frontTextTag->getTag(Sign::TAG_TEXT_BLOB); + if(!$textBlobTag instanceof StringTag){ + throw new PacketHandlingException("Invalid tag type " . get_debug_type($textBlobTag) . " for tag \"" . Sign::TAG_TEXT_BLOB . "\" in sign update data"); } - $this->session->getLogger()->debug("Invalid sign update data: " . base64_encode($packet->nbt->getEncodedNbt())); + try{ + $text = SignText::fromBlob($textBlobTag->getValue()); + }catch(\InvalidArgumentException $e){ + throw PacketHandlingException::wrap($e, "Invalid sign text update"); + } + + try{ + if(!$block->updateText($this->player, $text)){ + foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){ + $this->session->sendDataPacket($updatePacket); + } + } + }catch(\UnexpectedValueException $e){ + throw PacketHandlingException::wrap($e); + } + + return true; } return false;