mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
LevelDB: fixed server crash when corrupted / invalid blockstate NBT is encountered
This commit is contained in:
parent
e61aaaccca
commit
1a046c6cd5
@ -29,6 +29,7 @@ use pocketmine\data\bedrock\BiomeIds;
|
|||||||
use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap;
|
use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap;
|
||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
|
use pocketmine\nbt\NbtException;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\TreeRoot;
|
use pocketmine\nbt\TreeRoot;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
@ -157,6 +158,9 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
|||||||
BedrockWorldData::generate($path, $name, $options);
|
BedrockWorldData::generate($path, $name, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws CorruptedChunkException
|
||||||
|
*/
|
||||||
protected function deserializePaletted(BinaryStream $stream) : PalettedBlockArray{
|
protected function deserializePaletted(BinaryStream $stream) : PalettedBlockArray{
|
||||||
$bitsPerBlock = $stream->getByte() >> 1;
|
$bitsPerBlock = $stream->getByte() >> 1;
|
||||||
|
|
||||||
@ -169,13 +173,18 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
|
|||||||
$palette = [];
|
$palette = [];
|
||||||
$idMap = LegacyBlockIdToStringIdMap::getInstance();
|
$idMap = LegacyBlockIdToStringIdMap::getInstance();
|
||||||
for($i = 0, $paletteSize = $stream->getLInt(); $i < $paletteSize; ++$i){
|
for($i = 0, $paletteSize = $stream->getLInt(); $i < $paletteSize; ++$i){
|
||||||
$offset = $stream->getOffset();
|
try{
|
||||||
$tag = $nbt->read($stream->getBuffer(), $offset)->mustGetCompoundTag();
|
$offset = $stream->getOffset();
|
||||||
$stream->setOffset($offset);
|
|
||||||
|
|
||||||
$id = $idMap->stringToLegacy($tag->getString("name")) ?? BlockLegacyIds::INFO_UPDATE;
|
$tag = $nbt->read($stream->getBuffer(), $offset)->mustGetCompoundTag();
|
||||||
$data = $tag->getShort("val");
|
$stream->setOffset($offset);
|
||||||
$palette[] = ($id << Block::INTERNAL_METADATA_BITS) | $data;
|
|
||||||
|
$id = $idMap->stringToLegacy($tag->getString("name")) ?? BlockLegacyIds::INFO_UPDATE;
|
||||||
|
$data = $tag->getShort("val");
|
||||||
|
$palette[] = ($id << Block::INTERNAL_METADATA_BITS) | $data;
|
||||||
|
}catch(NbtException $e){
|
||||||
|
throw new CorruptedChunkException("Invalid blockstate NBT at offset $i in paletted storage: " . $e->getMessage(), 0, $e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: exceptions
|
//TODO: exceptions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user