ResourcePackManager: validate pack UUIDs

fixes CrashArchive ##12248760
This commit is contained in:
Dylan K. Taylor 2025-02-23 19:45:38 +00:00
parent 77be5f8e25
commit 3050af0bc0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -26,6 +26,7 @@ namespace pocketmine\resourcepacks;
use pocketmine\utils\Config;
use pocketmine\utils\Filesystem;
use pocketmine\utils\Utils;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Filesystem\Path;
use function array_keys;
use function copy;
@ -103,9 +104,14 @@ class ResourcePackManager{
try{
$newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
$this->resourcePacks[] = $newPack;
$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->resourcePacks[] = $newPack;
$keyPath = Path::join($this->path, $pack . ".key");
if(file_exists($keyPath)){
@ -190,6 +196,11 @@ class ResourcePackManager{
$resourcePacks = [];
foreach($resourceStack as $pack){
$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])){
throw new \InvalidArgumentException("Cannot load two resource pack with the same UUID ($uuid)");
}