forward-port of 2f47597d75b514944a2f3f5d293f2fb72dd7fb56 as best it fits

This commit is contained in:
Dylan K. Taylor 2020-05-13 13:28:35 +01:00
parent 84f41153e9
commit 45f9c61d0f
2 changed files with 10 additions and 3 deletions

View File

@ -111,8 +111,11 @@ class BedrockWorldData extends BaseNbtWorldData{
} }
protected function load() : CompoundTag{ protected function load() : CompoundTag{
$rawLevelData = file_get_contents($this->dataPath); $rawLevelData = @file_get_contents($this->dataPath);
if($rawLevelData === false or strlen($rawLevelData) <= 8){ if($rawLevelData === false){
throw new CorruptedWorldException("Failed to read level.dat (permission denied or doesn't exist)");
}
if(strlen($rawLevelData) <= 8){
throw new CorruptedWorldException("Truncated level.dat"); throw new CorruptedWorldException("Truncated level.dat");
} }
$nbt = new LittleEndianNbtSerializer(); $nbt = new LittleEndianNbtSerializer();

View File

@ -75,9 +75,13 @@ class JavaWorldData extends BaseNbtWorldData{
} }
protected function load() : CompoundTag{ protected function load() : CompoundTag{
$rawLevelData = @file_get_contents($this->dataPath);
if($rawLevelData === false){
throw new CorruptedWorldException("Failed to read level.dat (permission denied or doesn't exist)");
}
$nbt = new BigEndianNbtSerializer(); $nbt = new BigEndianNbtSerializer();
try{ try{
$worldData = $nbt->readCompressed(file_get_contents($this->dataPath))->mustGetCompoundTag(); $worldData = $nbt->readCompressed($rawLevelData)->mustGetCompoundTag();
}catch(NbtDataException $e){ }catch(NbtDataException $e){
throw new CorruptedWorldException($e->getMessage(), 0, $e); throw new CorruptedWorldException($e->getMessage(), 0, $e);
} }