Detect really big corrupted chunks, closes #2471

This commit is contained in:
Shoghi Cervantes 2014-12-31 12:40:11 +01:00
parent 767800662c
commit 95b305ce87
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
2 changed files with 13 additions and 0 deletions

View File

@ -88,6 +88,12 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
$compression = ord(fgetc($this->filePointer));
}
if($length >= self::MAX_SECTOR_LENGTH){
MainLogger::getLogger()->error("Corrupted chunk header detected");
return false;
}
if($length > ($this->locationTable[$index][1] << 12)){ //Invalid chunk, bigger than defined number of sectors
MainLogger::getLogger()->error("Corrupted chunk detected");
$this->locationTable[$index][1] = $length >> 12;

View File

@ -38,6 +38,7 @@ class RegionLoader{
const VERSION = 1;
const COMPRESSION_GZIP = 1;
const COMPRESSION_ZLIB = 2;
const MAX_SECTOR_LENGTH = 32 << 12; //32 sectors
public static $COMPRESSION_LEVEL = 7;
protected $x;
@ -109,6 +110,12 @@ class RegionLoader{
$compression = ord(fgetc($this->filePointer));
}
if($length >= self::MAX_SECTOR_LENGTH){
MainLogger::getLogger()->error("Corrupted chunk header detected");
return false;
}
if($length > ($this->locationTable[$index][1] << 12)){ //Invalid chunk, bigger than defined number of sectors
MainLogger::getLogger()->error("Corrupted bigger chunk detected");
$this->locationTable[$index][1] = $length >> 12;