format/leveldb: fix crash on truncated level.dat file

This commit is contained in:
Dylan K. Taylor 2020-01-08 09:55:03 +00:00
parent 27350c4673
commit e6a58e2690

View File

@ -126,8 +126,12 @@ class LevelDB extends BaseLevelProvider{
}
protected function loadLevelData() : void{
$rawLevelData = file_get_contents($this->getPath() . "level.dat");
if($rawLevelData === false or strlen($rawLevelData) <= 8){
throw new LevelException("Truncated level.dat");
}
$nbt = new LittleEndianNBTStream();
$levelData = $nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
$levelData = $nbt->read(substr($rawLevelData, 8));
if($levelData instanceof CompoundTag){
$this->levelData = $levelData;
}else{