Repository navigation
Fix GH-24337: JIT segfault when decrementing a non-numeric string property #24342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| --TEST-- | ||
| GH-24337 (JIT: segfault in zend_get_executed_lineno when decrementing a non-numeric string property) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please extend the test to also test with a bool/array
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 45e4b98. The test now covers bool and array for both ++ and --. Before the fix, function JIT also reported the wrong line for all of these, including the array TypeError. |
||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.file_update_protection=0 | ||
| opcache.jit_buffer_size=64M | ||
| opcache.jit=tracing | ||
| opcache.jit_hot_loop=2 | ||
| opcache.jit_hot_func=2 | ||
| opcache.jit_hot_return=2 | ||
| opcache.jit_hot_side_exit=1 | ||
| --EXTENSIONS-- | ||
| opcache | ||
| --FILE-- | ||
| <?php | ||
| set_error_handler(function ($errno, $errstr, $errfile, $errline) { | ||
| echo "$errstr on line $errline\n"; | ||
| }); | ||
| class Q { | ||
| public $pu = 0; | ||
| function run() { | ||
| for ($i = 0; $i < 2; $i++) { | ||
| $this->pu--; | ||
| } | ||
| } | ||
| function inc() { | ||
| for ($i = 0; $i < 2; $i++) { | ||
| $this->pu++; | ||
| } | ||
| } | ||
| } | ||
| class S extends Q { | ||
| public $pu = 'u'; | ||
| function run() { | ||
| parent::run(); | ||
| } | ||
| } | ||
| class B extends Q { | ||
| public $pu = true; | ||
| function run() { | ||
| parent::run(); | ||
| } | ||
| } | ||
| class A extends Q { | ||
| public $pu = []; | ||
| function run() { | ||
| parent::run(); | ||
| } | ||
| } | ||
| $objs = [new Q, new S, new B, new A]; | ||
| for ($k = 0; $k < 4; $k++) { | ||
| foreach ($objs as $o) { | ||
| try { | ||
| $o->run(); | ||
| } catch (TypeError $e) { | ||
| echo $e->getMessage(), " on line ", $e->getLine(), "\n"; | ||
| } | ||
| try { | ||
| $o->inc(); | ||
| } catch (TypeError $e) { | ||
| echo $e->getMessage(), " on line ", $e->getLine(), "\n"; | ||
| } | ||
| } | ||
| } | ||
| var_dump($objs[0]->pu, $objs[1]->pu, $objs[2]->pu, $objs[3]->pu); | ||
| ?> | ||
| --EXPECT-- | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Cannot decrement array on line 9 | ||
| Cannot increment array on line 14 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Cannot decrement array on line 9 | ||
| Cannot increment array on line 14 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Cannot decrement array on line 9 | ||
| Cannot increment array on line 14 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on non-numeric string has no effect and is deprecated on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Decrement on type bool has no effect, this will change in the next major version of PHP on line 9 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Increment on type bool has no effect, this will change in the next major version of PHP on line 14 | ||
| Cannot decrement array on line 9 | ||
| Cannot increment array on line 14 | ||
| int(0) | ||
| string(2) "ac" | ||
| bool(true) | ||
| array(0) { | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think MAY_BE_NULL may be excluded too for increment opcodes, but this is rare so probably not worth it. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be correct: increment_function() turns null into 1 without a notice, and zend_may_throw_ex() already leaves NULL out for PRE/POST_INC. But here var_info is either all of MAY_BE_ANY or the single type from the trace guard. So it only changes the code when the property is exactly null at trace time, and after one ++ it is an int and the guard exits. I left it out to keep the same mask as the CV path in zend_jit_inc_dec(). Happy to add it if you prefer.