AvailableEnchantmentRegistry: reject non-string tags

fixes https://crash.pmmp.io/view/12627328
This commit is contained in:
Dylan K. Taylor 2025-04-20 16:44:23 +01:00
parent f661443ec7
commit 2548422973
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 4 additions and 1 deletions

View File

@ -28,6 +28,7 @@ use pocketmine\item\enchantment\ItemEnchantmentTags as Tags;
use pocketmine\item\enchantment\VanillaEnchantments as Enchantments; use pocketmine\item\enchantment\VanillaEnchantments as Enchantments;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\utils\SingletonTrait; use pocketmine\utils\SingletonTrait;
use pocketmine\utils\Utils;
use function array_filter; use function array_filter;
use function array_values; use function array_values;
use function count; use function count;
@ -129,6 +130,7 @@ final class AvailableEnchantmentRegistry{
if(!$this->isRegistered($enchantment)){ if(!$this->isRegistered($enchantment)){
throw new \LogicException("Cannot set primary item tags for non-registered enchantment"); throw new \LogicException("Cannot set primary item tags for non-registered enchantment");
} }
Utils::validateArrayValueType($tags, fn(string $v) => 1);
$this->primaryItemTags[spl_object_id($enchantment)] = array_values($tags); $this->primaryItemTags[spl_object_id($enchantment)] = array_values($tags);
} }
@ -152,6 +154,7 @@ final class AvailableEnchantmentRegistry{
if(!$this->isRegistered($enchantment)){ if(!$this->isRegistered($enchantment)){
throw new \LogicException("Cannot set secondary item tags for non-registered enchantment"); throw new \LogicException("Cannot set secondary item tags for non-registered enchantment");
} }
Utils::validateArrayValueType($tags, fn(string $v) => 1);
$this->secondaryItemTags[spl_object_id($enchantment)] = array_values($tags); $this->secondaryItemTags[spl_object_id($enchantment)] = array_values($tags);
} }

View File

@ -584,7 +584,7 @@ final class Utils{
/** /**
* @phpstan-template TMemberType * @phpstan-template TMemberType
* @phpstan-param array<mixed, TMemberType> $array * @phpstan-param array<mixed, TMemberType> $array
* @phpstan-param \Closure(TMemberType) : void $validator * @phpstan-param \Closure(TMemberType) : mixed $validator
*/ */
public static function validateArrayValueType(array $array, \Closure $validator) : void{ public static function validateArrayValueType(array $array, \Closure $validator) : void{
foreach(Utils::promoteKeys($array) as $k => $v){ foreach(Utils::promoteKeys($array) as $k => $v){