diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index f02f3e294..948386c37 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -50,7 +50,7 @@ class Water extends Liquid{ public function onEntityCollide(Entity $entity) : void{ $entity->resetFallDistance(); - if($entity->fireTicks > 0){ + if($entity->isOnFire()){ $entity->extinguish(); } diff --git a/src/pocketmine/command/defaults/EnchantCommand.php b/src/pocketmine/command/defaults/EnchantCommand.php index 238e91aa2..c40886297 100644 --- a/src/pocketmine/command/defaults/EnchantCommand.php +++ b/src/pocketmine/command/defaults/EnchantCommand.php @@ -77,7 +77,15 @@ class EnchantCommand extends VanillaCommand{ return true; } - $item->addEnchantment(new EnchantmentInstance($enchantment, (int) ($args[2] ?? 1))); + $level = 1; + if(isset($args[2])){ + $level = $this->getBoundedInt($sender, $args[2], 1, $enchantment->getMaxLevel()); + if($level === null){ + return false; + } + } + + $item->addEnchantment(new EnchantmentInstance($enchantment, $level)); $player->getInventory()->setItemInHand($item); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index f8b67ce8c..2b0977652 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -327,7 +327,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /** @var int */ public $lastUpdate; /** @var int */ - public $fireTicks = 0; + protected $fireTicks = 0; /** @var bool */ public $canCollide = true; @@ -925,8 +925,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public function setOnFire(int $seconds) : void{ $ticks = $seconds * 20; - if($ticks > $this->fireTicks){ - $this->fireTicks = $ticks; + if($ticks > $this->getFireTicks()){ + $this->setFireTicks($ticks); } $this->setGenericFlag(self::DATA_FLAG_ONFIRE, true); @@ -941,8 +941,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /** * @param int $fireTicks + * @throws \InvalidArgumentException */ public function setFireTicks(int $fireTicks) : void{ + if($fireTicks < 0 or $fireTicks > 0x7fff){ + throw new \InvalidArgumentException("Fire ticks must be in range 0 ... " . 0x7fff . ", got $fireTicks"); + } $this->fireTicks = $fireTicks; } diff --git a/src/pocketmine/entity/projectile/Projectile.php b/src/pocketmine/entity/projectile/Projectile.php index d6e9ca3e2..2a1ebb9bf 100644 --- a/src/pocketmine/entity/projectile/Projectile.php +++ b/src/pocketmine/entity/projectile/Projectile.php @@ -314,7 +314,7 @@ abstract class Projectile extends Entity{ $entityHit->attack($ev); - if($this->fireTicks > 0){ + if($this->isOnFire()){ $ev = new EntityCombustByEntityEvent($this, $entityHit, 5); $ev->call(); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/level/format/io/region/RegionLoader.php b/src/pocketmine/level/format/io/region/RegionLoader.php index 3ba056815..f3b35ef82 100644 --- a/src/pocketmine/level/format/io/region/RegionLoader.php +++ b/src/pocketmine/level/format/io/region/RegionLoader.php @@ -45,6 +45,7 @@ use function str_pad; use function stream_set_read_buffer; use function stream_set_write_buffer; use function strlen; +use function substr; use function time; use function touch; use function unpack; @@ -126,8 +127,11 @@ class RegionLoader{ } fseek($this->filePointer, $this->locationTable[$index][0] << 12); - $length = Binary::readInt(fread($this->filePointer, 4)); - $compression = ord(fgetc($this->filePointer)); + $prefix = fread($this->filePointer, 4); + if($prefix === false or strlen($prefix) !== 4){ + throw new CorruptedChunkException("Corrupted chunk header detected (unexpected end of file reading length prefix)"); + } + $length = Binary::readInt($prefix); if($length <= 0 or $length > self::MAX_SECTOR_LENGTH){ //Not yet generated / corrupted if($length >= self::MAX_SECTOR_LENGTH){ @@ -142,17 +146,19 @@ class RegionLoader{ \GlobalLogger::get()->error("Corrupted bigger chunk detected (bigger than number of sectors given in header)"); $this->locationTable[$index][1] = $length >> 12; $this->writeLocationIndex($index); - }elseif($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){ + } + + $chunkData = fread($this->filePointer, $length); + if($chunkData === false or strlen($chunkData) !== $length){ + throw new CorruptedChunkException("Corrupted chunk detected (unexpected end of file reading chunk data)"); + } + + $compression = ord($chunkData[0]); + if($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){ throw new CorruptedChunkException("Invalid compression type (got $compression, expected " . self::COMPRESSION_ZLIB . " or " . self::COMPRESSION_GZIP . ")"); } - $chunkData = fread($this->filePointer, $length - 1); - if($chunkData === false){ - throw new CorruptedChunkException("Corrupted chunk detected (failed to read chunk data from disk)"); - - } - - return $chunkData; + return substr($chunkData, 1); } public function chunkExists(int $x, int $z) : bool{