mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
world IO: fixed crashes when garbage data found in tile/entity NBT data
This commit is contained in:
@ -26,6 +26,7 @@ namespace pocketmine\level\format\io\leveldb;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\io\BaseLevelProvider;
|
||||
use pocketmine\level\format\io\ChunkUtils;
|
||||
use pocketmine\level\format\io\exception\CorruptedChunkException;
|
||||
use pocketmine\level\format\io\exception\UnsupportedChunkFormatException;
|
||||
use pocketmine\level\format\SubChunk;
|
||||
use pocketmine\level\generator\Flat;
|
||||
@ -414,24 +415,27 @@ class LevelDB extends BaseLevelProvider{
|
||||
/** @var CompoundTag[] $entities */
|
||||
$entities = [];
|
||||
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){
|
||||
$entities = $nbt->read($entityData, true);
|
||||
if(!is_array($entities)){
|
||||
$entities = [$entities];
|
||||
}
|
||||
}
|
||||
|
||||
/** @var CompoundTag $entityNBT */
|
||||
foreach($entities as $entityNBT){
|
||||
if($entityNBT->hasTag("id", IntTag::class)){
|
||||
$entityNBT->setInt("id", $entityNBT->getInt("id") & 0xff); //remove type flags - TODO: use these instead of removing them)
|
||||
$entityTags = $nbt->read($entityData, true);
|
||||
foreach((is_array($entityTags) ? $entityTags : [$entityTags]) as $entityTag){
|
||||
if(!($entityTag instanceof CompoundTag)){
|
||||
throw new CorruptedChunkException("Entity root tag should be TAG_Compound");
|
||||
}
|
||||
if($entityTag->hasTag("id", IntTag::class)){
|
||||
$entityTag->setInt("id", $entityTag->getInt("id") & 0xff); //remove type flags - TODO: use these instead of removing them)
|
||||
}
|
||||
$entities[] = $entityTag;
|
||||
}
|
||||
}
|
||||
|
||||
/** @var CompoundTag[] $tiles */
|
||||
$tiles = [];
|
||||
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){
|
||||
$tiles = $nbt->read($tileData, true);
|
||||
if(!is_array($tiles)){
|
||||
$tiles = [$tiles];
|
||||
$tileTags = $nbt->read($tileData, true);
|
||||
foreach((is_array($tileTags) ? $tileTags : [$tileTags]) as $tileTag){
|
||||
if(!($tileTag instanceof CompoundTag)){
|
||||
throw new CorruptedChunkException("Tile root tag should be TAG_Compound");
|
||||
}
|
||||
$tiles[] = $tileTag;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user