mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
Catch corrupted chunk data errors
This commit is contained in:
parent
7b7bbe9105
commit
8249cac592
@ -133,14 +133,19 @@ class Chunk extends BaseChunk{
|
|||||||
*/
|
*/
|
||||||
public static function fromBinary($data, LevelProvider $provider = null){
|
public static function fromBinary($data, LevelProvider $provider = null){
|
||||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||||
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
|
|
||||||
$chunk = $nbt->getData();
|
try{
|
||||||
|
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
|
||||||
|
$chunk = $nbt->getData();
|
||||||
|
|
||||||
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Chunk($provider instanceof LevelProvider ? $provider : Anvil::class, $chunk->Level);
|
||||||
|
}catch (\Exception $e){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Chunk($provider instanceof LevelProvider ? $provider : Anvil::class, $chunk->Level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toBinary(){
|
public function toBinary(){
|
||||||
|
@ -255,14 +255,19 @@ class Chunk extends BaseFullChunk{
|
|||||||
*/
|
*/
|
||||||
public static function fromBinary($data, LevelProvider $provider = null){
|
public static function fromBinary($data, LevelProvider $provider = null){
|
||||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||||
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
|
|
||||||
$chunk = $nbt->getData();
|
|
||||||
|
|
||||||
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
try{
|
||||||
|
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
|
||||||
|
$chunk = $nbt->getData();
|
||||||
|
|
||||||
|
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Chunk($provider instanceof LevelProvider ? $provider : McRegion::class, $chunk->Level);
|
||||||
|
}catch (\Exception $e){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Chunk($provider instanceof LevelProvider ? $provider : McRegion::class, $chunk->Level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toBinary(){
|
public function toBinary(){
|
||||||
|
@ -212,11 +212,14 @@ class RegionLoader{
|
|||||||
if($length <= 1){
|
if($length <= 1){
|
||||||
$this->locationTable[$i] = [0, 0, 0]; //Non-generated chunk, remove it from index
|
$this->locationTable[$i] = [0, 0, 0]; //Non-generated chunk, remove it from index
|
||||||
}
|
}
|
||||||
$chunk = zlib_decode(substr($chunk, 5));
|
|
||||||
if(strlen($chunk) <= 1){
|
try{
|
||||||
|
$chunk = zlib_decode(substr($chunk, 5));
|
||||||
|
}catch (\Exception $e){
|
||||||
$this->locationTable[$i] = [0, 0, 0]; //Corrupted chunk, remove it
|
$this->locationTable[$i] = [0, 0, 0]; //Corrupted chunk, remove it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$chunk = chr(self::COMPRESSION_ZLIB) . zlib_encode($chunk, 15, 9);
|
$chunk = chr(self::COMPRESSION_ZLIB) . zlib_encode($chunk, 15, 9);
|
||||||
$chunk = Binary::writeInt(strlen($chunk)) . $chunk;
|
$chunk = Binary::writeInt(strlen($chunk)) . $chunk;
|
||||||
$sectors = (int) ceil(strlen($chunk) / 4096);
|
$sectors = (int) ceil(strlen($chunk) / 4096);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user