Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fixed bug #80186
This commit is contained in:
Nikita Popov 2020-10-09 16:59:01 +02:00
commit 623bf39e9c
3 changed files with 121 additions and 50 deletions

View File

@ -6484,14 +6484,7 @@ ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, JMP_ADDR)
} else if (OP1_TYPE != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(array_ptr);
if (!zobj->ce->get_iterator) {
HashTable *properties;
result = EX_VAR(opline->result.var);
ZVAL_OBJ(result, zobj);
if (OP1_TYPE != IS_TMP_VAR) {
GC_ADDREF(zobj);
}
properties = zobj->properties;
HashTable *properties = zobj->properties;
if (properties) {
if (UNEXPECTED(GC_REFCOUNT(properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) {
@ -6502,8 +6495,17 @@ ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, JMP_ADDR)
} else {
properties = zobj->handlers->get_properties(zobj);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
if (zend_hash_num_elements(properties) == 0) {
ZEND_VM_C_GOTO(fe_reset_r_empty);
}
result = EX_VAR(opline->result.var);
ZVAL_COPY_VALUE(result, array_ptr);
if (OP1_TYPE != IS_TMP_VAR) {
Z_ADDREF_P(array_ptr);
}
Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
FREE_OP1_IF_VAR();
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -6520,6 +6522,7 @@ ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, JMP_ADDR)
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_type_name(array_ptr));
ZEND_VM_C_LABEL(fe_reset_r_empty):
ZVAL_UNDEF(EX_VAR(opline->result.var));
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
FREE_OP1();
@ -6569,6 +6572,7 @@ ZEND_VM_COLD_CONST_HANDLER(125, ZEND_FE_RESET_RW, CONST|TMP|VAR|CV, JMP_ADDR)
ZEND_VM_NEXT_OPCODE();
} else if (OP1_TYPE != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
HashTable *properties;
if (OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) {
if (array_ptr == array_ref) {
ZVAL_NEW_REF(array_ref, array_ref);
@ -6587,8 +6591,14 @@ ZEND_VM_COLD_CONST_HANDLER(125, ZEND_FE_RESET_RW, CONST|TMP|VAR|CV, JMP_ADDR)
}
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
properties = Z_OBJPROP_P(array_ptr);
if (zend_hash_num_elements(properties) == 0) {
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
FREE_OP1_VAR_PTR();
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {

View File

@ -4793,14 +4793,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER(
} else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(array_ptr);
if (!zobj->ce->get_iterator) {
HashTable *properties;
result = EX_VAR(opline->result.var);
ZVAL_OBJ(result, zobj);
if (IS_CONST != IS_TMP_VAR) {
GC_ADDREF(zobj);
}
properties = zobj->properties;
HashTable *properties = zobj->properties;
if (properties) {
if (UNEXPECTED(GC_REFCOUNT(properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) {
@ -4811,7 +4804,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER(
} else {
properties = zobj->handlers->get_properties(zobj);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
if (zend_hash_num_elements(properties) == 0) {
goto fe_reset_r_empty;
}
result = EX_VAR(opline->result.var);
ZVAL_COPY_VALUE(result, array_ptr);
if (IS_CONST != IS_TMP_VAR) {
Z_ADDREF_P(array_ptr);
}
Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -4827,6 +4830,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER(
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_type_name(array_ptr));
fe_reset_r_empty:
ZVAL_UNDEF(EX_VAR(opline->result.var));
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
@ -4876,6 +4880,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_
ZEND_VM_NEXT_OPCODE();
} else if (IS_CONST != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
HashTable *properties;
if (IS_CONST == IS_VAR || IS_CONST == IS_CV) {
if (array_ptr == array_ref) {
ZVAL_NEW_REF(array_ref, array_ref);
@ -4894,7 +4899,14 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_
}
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
properties = Z_OBJPROP_P(array_ptr);
if (zend_hash_num_elements(properties) == 0) {
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -18788,14 +18800,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE
} else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(array_ptr);
if (!zobj->ce->get_iterator) {
HashTable *properties;
result = EX_VAR(opline->result.var);
ZVAL_OBJ(result, zobj);
if (IS_TMP_VAR != IS_TMP_VAR) {
GC_ADDREF(zobj);
}
properties = zobj->properties;
HashTable *properties = zobj->properties;
if (properties) {
if (UNEXPECTED(GC_REFCOUNT(properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) {
@ -18806,7 +18811,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE
} else {
properties = zobj->handlers->get_properties(zobj);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
if (zend_hash_num_elements(properties) == 0) {
goto fe_reset_r_empty;
}
result = EX_VAR(opline->result.var);
ZVAL_COPY_VALUE(result, array_ptr);
if (IS_TMP_VAR != IS_TMP_VAR) {
Z_ADDREF_P(array_ptr);
}
Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -18823,6 +18838,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_type_name(array_ptr));
fe_reset_r_empty:
ZVAL_UNDEF(EX_VAR(opline->result.var));
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
@ -18872,6 +18888,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(Z
ZEND_VM_NEXT_OPCODE();
} else if (IS_TMP_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
HashTable *properties;
if (IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) {
if (array_ptr == array_ref) {
ZVAL_NEW_REF(array_ref, array_ref);
@ -18890,7 +18907,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(Z
}
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
properties = Z_OBJPROP_P(array_ptr);
if (zend_hash_num_elements(properties) == 0) {
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -21338,14 +21362,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE
} else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(array_ptr);
if (!zobj->ce->get_iterator) {
HashTable *properties;
result = EX_VAR(opline->result.var);
ZVAL_OBJ(result, zobj);
if (IS_VAR != IS_TMP_VAR) {
GC_ADDREF(zobj);
}
properties = zobj->properties;
HashTable *properties = zobj->properties;
if (properties) {
if (UNEXPECTED(GC_REFCOUNT(properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) {
@ -21356,8 +21373,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE
} else {
properties = zobj->handlers->get_properties(zobj);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
if (zend_hash_num_elements(properties) == 0) {
goto fe_reset_r_empty;
}
result = EX_VAR(opline->result.var);
ZVAL_COPY_VALUE(result, array_ptr);
if (IS_VAR != IS_TMP_VAR) {
Z_ADDREF_P(array_ptr);
}
Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -21374,6 +21400,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_type_name(array_ptr));
fe_reset_r_empty:
ZVAL_UNDEF(EX_VAR(opline->result.var));
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
@ -21423,6 +21450,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(Z
ZEND_VM_NEXT_OPCODE();
} else if (IS_VAR != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
HashTable *properties;
if (IS_VAR == IS_VAR || IS_VAR == IS_CV) {
if (array_ptr == array_ref) {
ZVAL_NEW_REF(array_ref, array_ref);
@ -21441,8 +21469,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(Z
}
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
properties = Z_OBJPROP_P(array_ptr);
if (zend_hash_num_elements(properties) == 0) {
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -38040,14 +38074,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN
} else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
zend_object *zobj = Z_OBJ_P(array_ptr);
if (!zobj->ce->get_iterator) {
HashTable *properties;
result = EX_VAR(opline->result.var);
ZVAL_OBJ(result, zobj);
if (IS_CV != IS_TMP_VAR) {
GC_ADDREF(zobj);
}
properties = zobj->properties;
HashTable *properties = zobj->properties;
if (properties) {
if (UNEXPECTED(GC_REFCOUNT(properties) > 1)) {
if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) {
@ -38058,7 +38085,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN
} else {
properties = zobj->handlers->get_properties(zobj);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
if (zend_hash_num_elements(properties) == 0) {
goto fe_reset_r_empty;
}
result = EX_VAR(opline->result.var);
ZVAL_COPY_VALUE(result, array_ptr);
if (IS_CV != IS_TMP_VAR) {
Z_ADDREF_P(array_ptr);
}
Z_FE_ITER_P(result) = zend_hash_iterator_add(properties, 0);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {
@ -38074,6 +38111,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN
}
} else {
zend_error(E_WARNING, "foreach() argument must be of type array|object, %s given", zend_zval_type_name(array_ptr));
fe_reset_r_empty:
ZVAL_UNDEF(EX_VAR(opline->result.var));
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t)-1;
@ -38123,6 +38161,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZE
ZEND_VM_NEXT_OPCODE();
} else if (IS_CV != IS_CONST && EXPECTED(Z_TYPE_P(array_ptr) == IS_OBJECT)) {
if (!Z_OBJCE_P(array_ptr)->get_iterator) {
HashTable *properties;
if (IS_CV == IS_VAR || IS_CV == IS_CV) {
if (array_ptr == array_ref) {
ZVAL_NEW_REF(array_ref, array_ref);
@ -38141,7 +38180,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZE
}
Z_OBJ_P(array_ptr)->properties = zend_array_dup(Z_OBJ_P(array_ptr)->properties);
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(Z_OBJPROP_P(array_ptr), 0);
properties = Z_OBJPROP_P(array_ptr);
if (zend_hash_num_elements(properties) == 0) {
Z_FE_ITER_P(EX_VAR(opline->result.var)) = (uint32_t) -1;
ZEND_VM_JMP(OP_JMP_ADDR(opline, opline->op2));
}
Z_FE_ITER_P(EX_VAR(opline->result.var)) = zend_hash_iterator_add(properties, 0);
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
} else {

View File

@ -0,0 +1,15 @@
--TEST--
Bug #80186 (Segfault when iterating over FFI object)
--SKIPIF--
<?php
if (!extension_loaded('ffi')) die('skip ffi extension not available');
?>
--FILE--
<?php
$ffi = FFI::cdef('typedef int dummy;');
foreach ($ffi as $_) { }
foreach ($ffi as &$_) { }
?>
===DONE===
--EXPECT--
===DONE===