mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #5327 - add check to prevent OOMing on very large conditionals
This commit is contained in:
parent
641587635d
commit
5e8219b613
@ -87,6 +87,31 @@ class Algebra
|
||||
*/
|
||||
public static function simplifyCNF(array $clauses): array
|
||||
{
|
||||
$clause_count = count($clauses);
|
||||
|
||||
if ($clause_count > 50) {
|
||||
$all_has_unknown = true;
|
||||
|
||||
foreach ($clauses as $clause) {
|
||||
$clause_has_unknown = false;
|
||||
foreach ($clause->possibilities as $key => $_) {
|
||||
if ($key[0] === '*') {
|
||||
$clause_has_unknown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$clause_has_unknown) {
|
||||
$all_has_unknown = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($all_has_unknown) {
|
||||
return $clauses;
|
||||
}
|
||||
}
|
||||
|
||||
$cloned_clauses = [];
|
||||
|
||||
// avoid strict duplicates
|
||||
|
@ -1014,6 +1014,23 @@ class SwitchTypeTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'noCrashWithComplexMethodCallSwitches' => [
|
||||
'<?php
|
||||
function fromFoo(): int {
|
||||
switch (true) {
|
||||
case (rand(0, 1) && rand(0, 2)):
|
||||
case (rand(0, 3) && rand(0, 4)):
|
||||
case (rand(0, 5) && rand(0, 6)):
|
||||
case (rand(0, 7) && rand(0, 8)):
|
||||
case (rand(0, 7) && rand(0, 8)):
|
||||
case (rand(0, 7) && rand(0, 8)):
|
||||
case (rand(0, 7) && rand(0, 8)):
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user