Fixed the disaster of packet receive error handling

This commit is contained in:
Dylan K. Taylor
2019-01-16 19:52:41 +00:00
parent ddc2bed63f
commit 23269da1a6
19 changed files with 126 additions and 55 deletions

View File

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\BadPacketException;
use pocketmine\utils\Binary;
use pocketmine\utils\BinaryDataException;
class PacketPool{
/** @var \SplFixedArray<DataPacket> */
@ -175,10 +177,15 @@ class PacketPool{
* @param string $buffer
*
* @return DataPacket
* @throws BadPacketException
*/
public static function getPacket(string $buffer) : DataPacket{
$offset = 0;
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
try{
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
}catch(BinaryDataException $e){
throw new BadPacketException("Packet is too short");
}
$pk->setBuffer($buffer, $offset);
return $pk;