From 45f9c61d0f9bf1fbe7540ec1b19973feb399d1d0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 13 May 2020 13:28:35 +0100 Subject: [PATCH] forward-port of 2f47597d75b514944a2f3f5d293f2fb72dd7fb56 as best it fits --- src/world/format/io/data/BedrockWorldData.php | 7 +++++-- src/world/format/io/data/JavaWorldData.php | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/world/format/io/data/BedrockWorldData.php b/src/world/format/io/data/BedrockWorldData.php index 5be66be8b..ad50b9ddd 100644 --- a/src/world/format/io/data/BedrockWorldData.php +++ b/src/world/format/io/data/BedrockWorldData.php @@ -111,8 +111,11 @@ class BedrockWorldData extends BaseNbtWorldData{ } protected function load() : CompoundTag{ - $rawLevelData = file_get_contents($this->dataPath); - if($rawLevelData === false or strlen($rawLevelData) <= 8){ + $rawLevelData = @file_get_contents($this->dataPath); + 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"); } $nbt = new LittleEndianNbtSerializer(); diff --git a/src/world/format/io/data/JavaWorldData.php b/src/world/format/io/data/JavaWorldData.php index 2b7f45598..271728f5d 100644 --- a/src/world/format/io/data/JavaWorldData.php +++ b/src/world/format/io/data/JavaWorldData.php @@ -75,9 +75,13 @@ class JavaWorldData extends BaseNbtWorldData{ } 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(); try{ - $worldData = $nbt->readCompressed(file_get_contents($this->dataPath))->mustGetCompoundTag(); + $worldData = $nbt->readCompressed($rawLevelData)->mustGetCompoundTag(); }catch(NbtDataException $e){ throw new CorruptedWorldException($e->getMessage(), 0, $e); }