mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
EntityDataHelper: prevent INF/NaN being loaded from disk to come back and break things after the fact
This commit is contained in:
parent
8efa299c65
commit
6d584cf008
@ -32,6 +32,8 @@ use pocketmine\nbt\tag\FloatTag;
|
|||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use function count;
|
use function count;
|
||||||
|
use function is_infinite;
|
||||||
|
use function is_nan;
|
||||||
|
|
||||||
final class EntityDataHelper{
|
final class EntityDataHelper{
|
||||||
|
|
||||||
@ -39,6 +41,18 @@ final class EntityDataHelper{
|
|||||||
//NOOP
|
//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
|
* @throws SavedDataLoadingException
|
||||||
*/
|
*/
|
||||||
@ -54,6 +68,8 @@ final class EntityDataHelper{
|
|||||||
if(count($values) !== 2){
|
if(count($values) !== 2){
|
||||||
throw new SavedDataLoadingException("Expected exactly 2 entries for 'Rotation'");
|
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());
|
return Location::fromObject($pos, $world, $values[0]->getValue(), $values[1]->getValue());
|
||||||
}
|
}
|
||||||
@ -74,6 +90,15 @@ final class EntityDataHelper{
|
|||||||
if(count($values) !== 3){
|
if(count($values) !== 3){
|
||||||
throw new SavedDataLoadingException("Expected exactly 3 entries in '$tagName' tag");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user