diff --git a/src/entity/EntityDataHelper.php b/src/entity/EntityDataHelper.php index f01a10bb7..607ea1c38 100644 --- a/src/entity/EntityDataHelper.php +++ b/src/entity/EntityDataHelper.php @@ -32,6 +32,8 @@ use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\ListTag; use pocketmine\world\World; use function count; +use function is_infinite; +use function is_nan; final class EntityDataHelper{ @@ -39,6 +41,18 @@ final class EntityDataHelper{ //NOOP } + /** + * @throws SavedDataLoadingException + */ + private static function validateFloat(string $tagName, string $component, float $value) : void{ + if(is_infinite($value)){ + throw new SavedDataLoadingException("$component component of '$tagName' contains invalid infinite value"); + } + if(is_nan($value)){ + throw new SavedDataLoadingException("$component component of '$tagName' contains invalid NaN value"); + } + } + /** * @throws SavedDataLoadingException */ @@ -54,6 +68,8 @@ final class EntityDataHelper{ if(count($values) !== 2){ throw new SavedDataLoadingException("Expected exactly 2 entries for 'Rotation'"); } + self::validateFloat("Rotation", "yaw", $values[0]->getValue()); + self::validateFloat("Rotation", "pitch", $values[1]->getValue()); return Location::fromObject($pos, $world, $values[0]->getValue(), $values[1]->getValue()); } @@ -74,6 +90,15 @@ final class EntityDataHelper{ if(count($values) !== 3){ throw new SavedDataLoadingException("Expected exactly 3 entries in '$tagName' tag"); } - return new Vector3($values[0]->getValue(), $values[1]->getValue(), $values[2]->getValue()); + + $x = $values[0]->getValue(); + $y = $values[1]->getValue(); + $z = $values[2]->getValue(); + + self::validateFloat($tagName, "x", $x); + self::validateFloat($tagName, "y", $y); + self::validateFloat($tagName, "z", $z); + + return new Vector3($x, $y, $z); } }