McRegion: Ignore files which don't have a valid file extension

previously a file with a 4-letter name ending in 'mca' in the region folder of a PMAnvil world would cause the world format to be unrecognized. This happens because strrpos() returns false when the substring isn't found, which gets coerced to 0 when used in addition.
This commit is contained in:
Dylan K. Taylor 2020-10-24 11:15:07 +01:00
parent 55ecac4c80
commit 0f8101d4a6

View File

@ -245,11 +245,13 @@ class McRegion extends BaseLevelProvider{
if($isValid){
$files = array_filter(scandir($path . "/region/", SCANDIR_SORT_NONE), function(string $file) : bool{
return substr($file, strrpos($file, ".") + 1, 2) === "mc"; //region file
$extPos = strrpos($file, ".");
return $extPos !== false && substr($file, $extPos + 1, 2) === "mc"; //region file
});
foreach($files as $f){
if(substr($f, strrpos($f, ".") + 1) !== static::REGION_FILE_EXTENSION){
$extPos = strrpos($f, ".");
if($extPos !== false && substr($f, $extPos + 1) !== static::REGION_FILE_EXTENSION){
$isValid = false;
break;
}