From 78ffad5ffc1016f584a502605542315631903b94 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 7 Dec 2021 16:41:52 +0000 Subject: [PATCH 1/3] World: add checks for tile position outside of world bounds, closes #4622 --- src/world/World.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/world/World.php b/src/world/World.php index 37236de22..2980493de 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2373,6 +2373,9 @@ class World implements ChunkManager{ if(!$pos->isValid() || $pos->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Tile world"); } + if(!$this->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ())){ + throw new \InvalidArgumentException("Tile position is outside the world bounds"); + } $chunkX = $pos->getFloorX() >> Chunk::COORD_BIT_SIZE; $chunkZ = $pos->getFloorZ() >> Chunk::COORD_BIT_SIZE; @@ -2530,6 +2533,8 @@ class World implements ChunkManager{ $logger->warning("Deleted unknown tile entity type " . $nbt->getString("id", "")); }elseif(!$this->isChunkLoaded($tile->getPosition()->getFloorX() >> Chunk::COORD_BIT_SIZE, $tile->getPosition()->getFloorZ() >> Chunk::COORD_BIT_SIZE)){ $logger->error("Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded"); + }elseif(!$this->isInWorld(($tilePosition = $tile->getPosition())->getFloorX(), $tilePosition->getFloorY(), $tilePosition->getFloorZ())){ + $logger->error("Cannot add tile with position outside the world bounds: x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z"); }elseif($this->getTile($tilePosition = $tile->getPosition()) !== null){ $logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position"); }else{ From e0eeb87ea09a10bb8c5aba9324df5baba019e091 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 7 Dec 2021 16:45:20 +0000 Subject: [PATCH 2/3] World: simplify tile position checking code --- src/world/World.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index 2980493de..6d3aa6712 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2531,11 +2531,15 @@ class World implements ChunkManager{ } if($tile === null){ $logger->warning("Deleted unknown tile entity type " . $nbt->getString("id", "")); - }elseif(!$this->isChunkLoaded($tile->getPosition()->getFloorX() >> Chunk::COORD_BIT_SIZE, $tile->getPosition()->getFloorZ() >> Chunk::COORD_BIT_SIZE)){ + continue; + } + + $tilePosition = $tile->getPosition(); + if(!$this->isChunkLoaded($tilePosition->getFloorX() >> Chunk::COORD_BIT_SIZE, $tilePosition->getFloorZ() >> Chunk::COORD_BIT_SIZE)){ $logger->error("Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded"); - }elseif(!$this->isInWorld(($tilePosition = $tile->getPosition())->getFloorX(), $tilePosition->getFloorY(), $tilePosition->getFloorZ())){ + }elseif(!$this->isInWorld($tilePosition->getFloorX(), $tilePosition->getFloorY(), $tilePosition->getFloorZ())){ $logger->error("Cannot add tile with position outside the world bounds: x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z"); - }elseif($this->getTile($tilePosition = $tile->getPosition()) !== null){ + }elseif($this->getTile($tilePosition) !== null){ $logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position"); }else{ $this->addTile($tile); From 3d9e19546fadc0dbcd834a8bf7b67ab7f65e2019 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 7 Dec 2021 23:35:45 +0000 Subject: [PATCH 3/3] EntityShootBowEvent: fixed incorrect field type --- src/event/entity/EntityShootBowEvent.php | 2 +- tests/phpstan/configs/actual-problems.neon | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/event/entity/EntityShootBowEvent.php b/src/event/entity/EntityShootBowEvent.php index 32f4f4d70..5a871f282 100644 --- a/src/event/entity/EntityShootBowEvent.php +++ b/src/event/entity/EntityShootBowEvent.php @@ -39,7 +39,7 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{ /** @var Item */ private $bow; - /** @var Projectile */ + /** @var Entity */ private $projectile; /** @var float */ private $force; diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index 52b727319..5776a837b 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -600,11 +600,6 @@ parameters: count: 1 path: ../../../src/entity/projectile/Projectile.php - - - message: "#^Property pocketmine\\\\event\\\\entity\\\\EntityShootBowEvent\\:\\:\\$projectile \\(pocketmine\\\\entity\\\\projectile\\\\Projectile\\) does not accept pocketmine\\\\entity\\\\Entity\\.$#" - count: 1 - path: ../../../src/event/entity/EntityShootBowEvent.php - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" count: 1