Fixed server crash on truncated varint in packet header

This commit is contained in:
Dylan K. Taylor 2021-02-16 20:38:15 +00:00
parent dff13a884f
commit 8dd61df7ac
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol\serializer;
use pocketmine\network\mcpe\protocol\Packet;
use pocketmine\network\mcpe\protocol\PacketDecodeException;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\utils\BinaryDataException;
class PacketBatch{
@ -44,7 +45,11 @@ class PacketBatch{
public function getPackets(PacketPool $packetPool, int $max) : \Generator{
$serializer = new PacketSerializer($this->buffer);
for($c = 0; $c < $max and !$serializer->feof(); ++$c){
try{
yield $c => $packetPool->getPacket($serializer->getString());
}catch(BinaryDataException $e){
throw new PacketDecodeException("Error decoding packet $c of batch: " . $e->getMessage(), 0, $e);
}
}
if(!$serializer->feof()){
throw new PacketDecodeException("Reached limit of $max packets in a single batch");