Skip to content

Prevent int overflow crash when comparing against PHP_INT_MAX/MIN#11715

Open
eyupcanakman wants to merge 1 commit intovimeo:6.xfrom
eyupcanakman:fix/int-range-overflow-11209
Open

Prevent int overflow crash when comparing against PHP_INT_MAX/MIN#11715
eyupcanakman wants to merge 1 commit intovimeo:6.xfrom
eyupcanakman:fix/int-range-overflow-11209

Conversation

@eyupcanakman
Copy link
Contributor

Fix #11209

reconcileIsGreaterThan computes $assertion->value + 1, which overflows from int to float when the assertion value is PHP_INT_MAX. The resulting float is passed to TIntRange::contains(int $i) under strict_types=1, causing a TypeError.

The same underflow happens in reconcileIsLessThan with PHP_INT_MIN - 1.

Added !is_int() guards after each arithmetic step. When overflow is detected, no integer can satisfy the comparison, so all integer types are removed from the union.

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 vimeo#11209.
@eyupcanakman eyupcanakman force-pushed the fix/int-range-overflow-11209 branch from b479a89 to bea0b2d Compare March 5, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug during initialization - TIntRange::contains(): Argument #1 ($i) must be of type int, float given

1 participant