Commit bea0b2d
committed
fix: prevent int overflow crash when comparing against PHP_INT_MAX/MIN
When an int is compared against PHP_INT_MAX (e.g. $v <= PHP_INT_MAX) and
psalm evaluates the negated assertion (> PHP_INT_MAX) in the else branch,
reconcileIsGreaterThan computes PHP_INT_MAX + 1, which silently overflows
from int to float. Passing that float to TIntRange::contains(int $i) under
strict_types=1 raises a fatal TypeError.
The same underflow occurs in reconcileIsLessThan when the assertion value
is PHP_INT_MIN.
Add !is_int() guards after each arithmetic step. When the guard fires, no
integer can satisfy the comparison (> PHP_INT_MAX or < PHP_INT_MIN), so all
TIntRange, TInt, and TLiteralInt types are removed from the union.
Fixes #11209.1 parent 551172c commit bea0b2d
File tree
2 files changed
+62
-1
lines changed- src/Psalm/Internal/Type
- tests
2 files changed
+62
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1964 | 1964 | | |
1965 | 1965 | | |
1966 | 1966 | | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
1967 | 1986 | | |
1968 | 1987 | | |
1969 | 1988 | | |
| |||
2013 | 2032 | | |
2014 | 2033 | | |
2015 | 2034 | | |
2016 | | - | |
| 2035 | + | |
2017 | 2036 | | |
2018 | 2037 | | |
2019 | 2038 | | |
| |||
2073 | 2092 | | |
2074 | 2093 | | |
2075 | 2094 | | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
2076 | 2114 | | |
2077 | 2115 | | |
2078 | 2116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1037 | 1060 | | |
1038 | 1061 | | |
1039 | 1062 | | |
| |||
0 commit comments