Skip to content

Commit

Permalink
Don't handle NAN/INF in movements
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Mar 23, 2021
1 parent 3333df3 commit fb20bb3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pocketmine/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@
use function gettype;
use function implode;
use function in_array;
use function is_infinite;
use function is_int;
use function is_nan;
use function is_object;
use function is_string;
use function json_encode;
Expand Down Expand Up @@ -2357,8 +2359,15 @@ public function chat(string $message) : bool{
}

public function handleMovePlayer(MovePlayerPacket $packet) : bool{
$newPos = $packet->position->round(4)->subtract(0, $this->baseOffset, 0);
$rawPos = $packet->position;
foreach([$rawPos->x, $rawPos->y, $rawPos->z, $packet->yaw, $packet->headYaw, $packet->pitch] as $float){
if(is_infinite($float) || is_nan($float)){
$this->server->getLogger()->debug("Invalid movement from " . $this->getName() . ", contains NAN/INF components");
return false;
}
}

$newPos = $rawPos->round(4)->subtract(0, $this->baseOffset, 0);
if($this->forceMoveSync !== null and $newPos->distanceSquared($this->forceMoveSync) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks
$this->server->getLogger()->debug("Got outdated pre-teleport movement from " . $this->getName() . ", received " . $newPos . ", expected " . $this->asVector3());
//Still getting movements from before teleport, ignore them
Expand Down

0 comments on commit fb20bb3

Please sign in to comment.