From 1d02c4f27684644e8361cf2a2bc5713adef9b95e Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 15 May 2024 07:08:13 +0200 Subject: [PATCH] Fix more potential for infinite recursion --- src/Type/ObjectType.php | 5 ++++- src/Type/RecursionGuard.php | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index c9e89e5841..cc2030bb4e 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -1248,10 +1248,13 @@ public function getEnumCases(): array public function isCallable(): TrinaryLogic { - $parametersAcceptors = $this->findCallableParametersAcceptors(); + $parametersAcceptors = RecursionGuard::run($this, fn () => $this->findCallableParametersAcceptors()); if ($parametersAcceptors === null) { return TrinaryLogic::createNo(); } + if ($parametersAcceptors instanceof ErrorType) { + return TrinaryLogic::createNo(); + } if ( count($parametersAcceptors) === 1 diff --git a/src/Type/RecursionGuard.php b/src/Type/RecursionGuard.php index 2149fb1015..8fd995882c 100644 --- a/src/Type/RecursionGuard.php +++ b/src/Type/RecursionGuard.php @@ -9,10 +9,11 @@ class RecursionGuard private static array $context = []; /** - * @param callable(): Type $callback - * + * @template T + * @param callable(): T $callback + * @return T|ErrorType */ - public static function run(Type $type, callable $callback): Type + public static function run(Type $type, callable $callback) { $key = $type->describe(VerbosityLevel::value()); if (isset(self::$context[$key])) {