LoginPacket: fixed error handling edge case with malformed chain data JSON

This commit is contained in:
Dylan K. Taylor
2020-05-06 21:46:35 +01:00
parent ed757c7207
commit 0b6d6306cf
2 changed files with 53 additions and 0 deletions

View File

@ -33,7 +33,9 @@ use pocketmine\network\mcpe\protocol\types\login\JwtChain;
use pocketmine\utils\BinaryDataException;
use pocketmine\utils\BinaryStream;
use function is_array;
use function is_object;
use function json_decode;
use function json_last_error_msg;
class LoginPacket extends DataPacket implements ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::LOGIN_PACKET;
@ -69,6 +71,9 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
$buffer = new BinaryStream($in->getString());
$chainDataJson = json_decode($buffer->get($buffer->getLInt()));
if(!is_object($chainDataJson)){
throw new PacketDecodeException("Failed decoding chain data JSON: " . json_last_error_msg());
}
$mapper = new \JsonMapper;
$mapper->bExceptionOnMissingData = true;
$mapper->bExceptionOnUndefinedProperty = true;