Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix GH-17447: Assertion failure when array popping a self addressing variable
  • Loading branch information
nielsdos committed Jan 16, 2025
2 parents a4fa1e7 + ae3ab37 commit d0d8e68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -3571,7 +3571,8 @@ PHP_FUNCTION(array_pop)
break;
}
}
RETVAL_COPY_DEREF(val);
RETVAL_COPY_VALUE(val);
ZVAL_UNDEF(val);

if (idx == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) {
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
Expand All @@ -3595,7 +3596,8 @@ PHP_FUNCTION(array_pop)
break;
}
}
RETVAL_COPY_DEREF(val);
RETVAL_COPY_VALUE(val);
ZVAL_UNDEF(val);

if (!p->key && (zend_long)p->h == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) {
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
Expand All @@ -3605,6 +3607,10 @@ PHP_FUNCTION(array_pop)
zend_hash_del_bucket(Z_ARRVAL_P(stack), p);
}
zend_hash_internal_pointer_reset(Z_ARRVAL_P(stack));

if (Z_ISREF_P(return_value)) {
zend_unwrap_reference(return_value);
}
}
/* }}} */

Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/array/gh17447.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-17447 (Assertion failure when array poping a self addressing variable)
--FILE--
<?php
$input[] = &$input;
var_dump(array_pop($input), $input);
?>
--EXPECT--
array(0) {
}
array(0) {
}

0 comments on commit d0d8e68

Please sign in to comment.