Repository navigation
Check open integer-range bounds for shift-left overflow - #6647
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix correctly handles both open bounds and includes comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes shift-left inference for open integer ranges by accounting for platform limits during overflow detection.
Changes:
- Checks unbounded range endpoints using
PHP_INT_MINandPHP_INT_MAX. - Updates affected shift-left expectations.
- Adds regression coverage for open ranges and the
u64()reader false positive.
| File | Description |
|---|---|
src/Reflection/InitializerExprTypeResolver.php |
Detects overflow at open integer-range bounds. |
tests/PHPStan/Analyser/nsrt/shift-left-unbounded-range.php |
Covers open bounds, zero/right shifts, and the reader regression. |
tests/PHPStan/Analyser/nsrt/integer-range-types.php |
Updates overflow-sensitive inferred types. |
tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php |
Verifies the false comparison warning is eliminated. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The core unit-test matrix, self-analysis matrix, generated baselines, and coding standard have passed. I also downloaded the PHAR built by this PR and ran the full passkeys analysis with its original configuration: no errors. The broader PHAR integration matrix is not green, but its current failures also occur in the earlier run https://github.com/phpstan/phpstan-src/actions/runs/36867554483, before this PR:
I have not changed those unrelated checks or their baselines. This account has read-only access to the upstream repository, so I cannot rerun its jobs. |
|
Final CI update: the core unit tests, self-analysis, coding standard, and generated baselines pass, but not all remaining failures are pre-existing. PocketMine is affected by this fix. At The other newly completed failures are:
The earlier comment's pre-existing-failure evidence applies to the specific jobs listed there, not to every failure in the final matrix. |
|
Hi, 2.2.x branch is not maintained anymore. |
a073615 to
40c807b
Compare
|
Thanks! Retargeted to I also applied the same fix to the native Turbo implementation added on The full PHP and native suites both pass (22,526 tests, 96,997 assertions, 75 skipped each), as do self-analysis in both modes, method/signature parity, the focused PHP/Turbo whole-walk differential, and the Turbo smoke differential (ALL OK). The updated branch has been pushed. |
…ow check phpstan/phpstan-src#6647 made an open positive-int << 12 return int, since it can overflow. RegionLoader passes getSectorCount() << 12 to fread(), and getSectorCount() is only positive-int, so the length is no longer int<1, max>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ow check phpstan/phpstan-src#6647 made an open positive-int << 12 return int, since it can overflow. RegionLoader passes getSectorCount() << 12 to fread(), and getSectorCount() is only positive-int, so the length is no longer int<1, max>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Check open integer-range bounds for shift-left overflow, using
PHP_INT_MINandPHP_INT_MAXwhen a bound isnull.Rebased onto
2.3.xafter2.2.xmaintenance ended. The PHP resolver and its native Turbo implementation contain the same fix, with differential coverage and the required Turbo version bump.The existing overflow check only checks finite bounds. For
int<0, max> << 8, it checks zero but skips the maximum, so the result incorrectly remains non-negative. The same problem affects open lower bounds.This causes a false
smaller.alwaysFalseerror in a big-endianu64()reader:The false positive first appears in 2.2.9. Git bisect identifies 1081ec4, whose bitwise OR range inference exposes the shift-left problem. The more recent finite-bound overflow check does not cover this case.
Tests
Initial validation on PHP 8.5, before retargeting from
2.2.x:Validation after rebasing onto
2.3.x(PHP 8.5):Original failure: https://github.com/shipmonk-rnd/passkeys/actions/runs/36873090362/job/110405538537
Task: https://app.asana.com/0/0/1219068476946134