diff --git a/src/pocketmine/block/Sign.php b/src/pocketmine/block/Sign.php index 3d055b3cb..0b1a9e416 100644 --- a/src/pocketmine/block/Sign.php +++ b/src/pocketmine/block/Sign.php @@ -36,6 +36,7 @@ use pocketmine\utils\TextFormat; use function array_map; use function assert; use function floor; +use function strlen; class Sign extends Transparent{ /** @var BlockIdentifierFlattened */ @@ -151,8 +152,16 @@ class Sign extends Transparent{ * @param SignText $text * * @return bool if the sign update was successful. + * @throws \UnexpectedValueException if the text payload is too large */ public function updateText(Player $author, SignText $text) : bool{ + $size = 0; + foreach($text->getLines() as $line){ + $size += strlen($line); + } + if($size > 1000){ + throw new \UnexpectedValueException($author->getName() . " tried to write $size bytes of text onto a sign (bigger than max 1000)"); + } $removeFormat = $author->getRemoveFormat(); $ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) use ($removeFormat){ return TextFormat::clean($line, $removeFormat); diff --git a/src/pocketmine/command/defaults/WhitelistCommand.php b/src/pocketmine/command/defaults/WhitelistCommand.php index c5d988f58..aed16e033 100644 --- a/src/pocketmine/command/defaults/WhitelistCommand.php +++ b/src/pocketmine/command/defaults/WhitelistCommand.php @@ -115,8 +115,12 @@ class WhitelistCommand extends VanillaCommand{ return true; } - private function badPerm(CommandSender $sender, string $perm) : bool{ - if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){ + private function badPerm(CommandSender $sender, string $subcommand) : bool{ + static $map = [ + "on" => "enable", + "off" => "disable" + ]; + if(!$sender->hasPermission("pocketmine.command.whitelist." . ($map[$subcommand] ?? $subcommand))){ $sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission")); return true; diff --git a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index b9677d658..8a969d907 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -464,8 +464,12 @@ class SimpleSessionHandler extends SessionHandler{ throw new BadPacketException("Invalid sign text update: " . $e->getMessage(), 0, $e); } - if(!$block->updateText($this->player, $text)){ - $this->player->getLevel()->sendBlocks([$this->player], [$block]); + try{ + if(!$block->updateText($this->player, $text)){ + $this->player->getLevel()->sendBlocks([$this->player], [$block]); + } + }catch(\UnexpectedValueException $e){ + throw new BadPacketException($e->getMessage(), 0, $e); } return true;