Commit f6f5b5b
committed
Fix GH-17144: type inference narrowing on ZEND_FETCH_DIM_W
FETCH_DIM_W stripped MAY_BE_ARRAY_EMPTY when key_type had any valid
key bit set. As the key operand's type widened across iterations
(e.g. from MAY_BE_ARRAY to MAY_BE_ARRAY|MAY_BE_LONG), key_type
transitioned from 0 to non-zero, flipping the strip from inactive to
active. The resulting type lost MAY_BE_ARRAY_EMPTY mid-iteration,
tripping the narrowing assertion.
Stripping unconditionally is unsound: $a = []; $a[$a] = 1; throws
before the write, leaving the array empty. Strip only when the key
operand is guaranteed a valid array key, i.e. when op2 is IS_UNUSED
(append) or t2 contains no MAY_BE_ARRAY or MAY_BE_OBJECT bits. As t2
widens, this condition can only flip from true to false, so the
result type monotonically gains MAY_BE_ARRAY_EMPTY back rather than
losing it.
Test covers both the original narrowing reproducer and the invalid-key
throw path.
Closes GH-171441 parent 9c08243 commit f6f5b5b
2 files changed
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3716 | 3716 | | |
3717 | 3717 | | |
3718 | 3718 | | |
3719 | | - | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
3720 | 3722 | | |
3721 | 3723 | | |
3722 | 3724 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments