mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-18 17:11:28 +00:00
ResourcePackManager: validate pack UUIDs
fixes CrashArchive ##12248760
This commit is contained in:
parent
77be5f8e25
commit
3050af0bc0
@ -26,6 +26,7 @@ namespace pocketmine\resourcepacks;
|
|||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
use pocketmine\utils\Filesystem;
|
use pocketmine\utils\Filesystem;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
use Symfony\Component\Filesystem\Path;
|
use Symfony\Component\Filesystem\Path;
|
||||||
use function array_keys;
|
use function array_keys;
|
||||||
use function copy;
|
use function copy;
|
||||||
@ -103,9 +104,14 @@ class ResourcePackManager{
|
|||||||
try{
|
try{
|
||||||
$newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
|
$newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
|
||||||
|
|
||||||
$this->resourcePacks[] = $newPack;
|
|
||||||
$index = strtolower($newPack->getPackId());
|
$index = strtolower($newPack->getPackId());
|
||||||
|
if(!Uuid::isValid($index)){
|
||||||
|
//TODO: we should use Uuid in ResourcePack interface directly but that would break BC
|
||||||
|
//for now we need to validate this here to make sure it doesn't cause crashes later on
|
||||||
|
throw new ResourcePackException("Invalid UUID ($index)");
|
||||||
|
}
|
||||||
$this->uuidList[$index] = $newPack;
|
$this->uuidList[$index] = $newPack;
|
||||||
|
$this->resourcePacks[] = $newPack;
|
||||||
|
|
||||||
$keyPath = Path::join($this->path, $pack . ".key");
|
$keyPath = Path::join($this->path, $pack . ".key");
|
||||||
if(file_exists($keyPath)){
|
if(file_exists($keyPath)){
|
||||||
@ -190,6 +196,11 @@ class ResourcePackManager{
|
|||||||
$resourcePacks = [];
|
$resourcePacks = [];
|
||||||
foreach($resourceStack as $pack){
|
foreach($resourceStack as $pack){
|
||||||
$uuid = strtolower($pack->getPackId());
|
$uuid = strtolower($pack->getPackId());
|
||||||
|
if(!Uuid::isValid($uuid)){
|
||||||
|
//TODO: we should use Uuid in ResourcePack interface directly but that would break BC
|
||||||
|
//for now we need to validate this here to make sure it doesn't cause crashes later on
|
||||||
|
throw new \InvalidArgumentException("Invalid resource pack UUID ($uuid)");
|
||||||
|
}
|
||||||
if(isset($uuidList[$uuid])){
|
if(isset($uuidList[$uuid])){
|
||||||
throw new \InvalidArgumentException("Cannot load two resource pack with the same UUID ($uuid)");
|
throw new \InvalidArgumentException("Cannot load two resource pack with the same UUID ($uuid)");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user