Skip to content

Commit

Permalink
Fix more potential for infinite recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 15, 2024
1 parent bb3da26 commit 1d02c4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/Type/RecursionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down

0 comments on commit 1d02c4f

Please sign in to comment.