Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ PHP NEWS
. Fix OSS-Fuzz #568005340 (FETCH_DIM_FUNC_ARG partial conversion). (ndossche)
. Fixed bug GH-24218 (Invalid opcode for count() of a literal array when
SCCP is disabled). (Lazizbek Ergashev)
. Fixed bug GH-24337 (JIT: segfault when decrementing a non-numeric string
property). (Lazizbek Ergashev)

- PDO:
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a
Expand Down
7 changes: 4 additions & 3 deletions ext/opcache/jit/zend_jit_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -15823,12 +15823,13 @@ static int zend_jit_incdec_obj(zend_jit_ctx *jit,
}

if (var_info & (MAY_BE_ANY - MAY_BE_LONG)) {
if (var_info & (MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) {
may_throw = 1;
}
if (if_long) {
ir_IF_FALSE_cold(if_long);
}
if (var_info & (MAY_BE_ANY - (MAY_BE_LONG|MAY_BE_DOUBLE))) {

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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.

may_throw = 1;
jit_SET_EX_OPLINE(jit, opline);
}
if (opline->opcode == ZEND_POST_INC_OBJ || opline->opcode == ZEND_POST_DEC_OBJ) {
jit_ZVAL_COPY(jit, res_addr, -1, var_addr, var_info, 1);
}
Expand Down
105 changes: 105 additions & 0 deletions ext/opcache/tests/jit/gh24337.phpt
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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) {
}
Loading