From 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 01/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From f684963a9624b5172d4ed3b1dbfaccac2643cfc7 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 02/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From cb12bed2b71108b5491182a6b22b9f0a46f5e769 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Wed, 25 Jan 2023 20:31:01 -0300 Subject: [PATCH 03/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/assign_dim_obj_null_return.phpt | 8 ++++---- Zend/tests/bug79790.phpt | 2 +- Zend/tests/bug79947.phpt | 2 +- Zend/tests/offset_array.phpt | 13 +++++++++++-- Zend/zend_execute.c | 12 ++++++++++++ 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 8f74bccc075f0..3d6e4746ed621 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type object diff --git a/Zend/tests/assign_dim_obj_null_return.phpt b/Zend/tests/assign_dim_obj_null_return.phpt index 0a2ea94c552d5..b2e56ed04528a 100644 --- a/Zend/tests/assign_dim_obj_null_return.phpt +++ b/Zend/tests/assign_dim_obj_null_return.phpt @@ -72,12 +72,12 @@ test(); ?> --EXPECT-- Cannot add element to the array as the next element is already occupied -Illegal offset type -Illegal offset type +Illegal offset type: cannot be of type array +Illegal offset type: cannot be of type object Cannot use a scalar value as an array Cannot add element to the array as the next element is already occupied -Illegal offset type -Illegal offset type +Illegal offset type: cannot be of type array +Illegal offset type: cannot be of type object Cannot use a scalar value as an array Attempt to assign property "foo" on true Attempt to assign property "foo" on true diff --git a/Zend/tests/bug79790.phpt b/Zend/tests/bug79790.phpt index 4fce25291bcb5..125f74aedc339 100644 --- a/Zend/tests/bug79790.phpt +++ b/Zend/tests/bug79790.phpt @@ -8,7 +8,7 @@ function b($a = array()[array ()]) { } ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %s:%d +Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %s:%d Stack trace: #0 %s(%d): b() #1 {main} diff --git a/Zend/tests/bug79947.phpt b/Zend/tests/bug79947.phpt index 906f58144b41d..edfbdaa0b754c 100644 --- a/Zend/tests/bug79947.phpt +++ b/Zend/tests/bug79947.phpt @@ -12,6 +12,6 @@ try { var_dump($array); ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type array array(0) { } diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 0109950cde848..47d7cc9f32e7e 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -30,6 +30,14 @@ try { echo $e->getMessage(), "\n"; } +try{ + $k = []; + $arr = ['foo']; + $arr[$k]; +}catch (Error $e){ + echo $e->getMessage(), "\n"; +} + echo "Done\n"; ?> --EXPECTF-- @@ -48,6 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type -Illegal offset type +Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type array +Illegal offset type: cannot be of type array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 3e1baa304197a..32bf0bc515d64 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2313,6 +2313,12 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval case IS_TRUE: value->lval = 1; return IS_LONG; + case IS_ARRAY: + zend_type_error("Illegal offset type: cannot be of type array"); + return IS_ARRAY; + case IS_OBJECT: + zend_type_error("Illegal offset type: cannot be of type object"); + return IS_OBJECT; default: zend_illegal_offset(); return IS_NULL; @@ -2387,6 +2393,12 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv case IS_TRUE: value->lval = 1; return IS_LONG; + case IS_ARRAY: + zend_type_error("Illegal offset type: cannot be of type array"); + return IS_ARRAY; + case IS_OBJECT: + zend_type_error("Illegal offset type: cannot be of type object"); + return IS_OBJECT; default: zend_illegal_offset(); return IS_NULL; From 0717f23ae0aa6f2f1bbc14cbcd1a7b27bdc191fd Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Wed, 25 Jan 2023 20:40:13 -0300 Subject: [PATCH 04/92] inform the type in the array displacement error message. --- ext/opcache/tests/jit/assign_dim_002.phpt | 6 +++--- ext/opcache/tests/jit/assign_dim_op_001.phpt | 4 ++-- ext/opcache/tests/jit/fetch_dim_rw_004.phpt | 2 +- tests/classes/tostring_001.phpt | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 3f713a6c6a6a9..4a03cc2641aca 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type +Illegal offset type: cannot be of type object array(1) { [0]=> array(2) { @@ -198,7 +198,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d int(1) @@ -221,7 +221,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Warning: Undefined variable $undef in %s on line %d NULL diff --git a/ext/opcache/tests/jit/assign_dim_op_001.phpt b/ext/opcache/tests/jit/assign_dim_op_001.phpt index a533cbe9c283b..f63a5de66938b 100644 --- a/ext/opcache/tests/jit/assign_dim_op_001.phpt +++ b/ext/opcache/tests/jit/assign_dim_op_001.phpt @@ -79,7 +79,7 @@ Warning: Undefined array key 2 in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d @@ -104,5 +104,5 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Unsupported operand types: null % string diff --git a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt index ea3fff88f1e45..65ad0e0d5a06a 100644 --- a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt +++ b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt @@ -18,7 +18,7 @@ Stack trace: #0 %sfetch_dim_rw_004.php(5): {closure}(2, 'Undefined varia...', '%s', 5) #1 {main} -Next TypeError: Illegal offset type in %sfetch_dim_rw_004.php:5 +Next TypeError: Illegal offset type: cannot be of type array in %sfetch_dim_rw_004.php:5 Stack trace: #0 {main} thrown in %sfetch_dim_rw_004.php on line 5 diff --git a/tests/classes/tostring_001.phpt b/tests/classes/tostring_001.phpt index abf41f97cdaca..df54e08a002cf 100644 --- a/tests/classes/tostring_001.phpt +++ b/tests/classes/tostring_001.phpt @@ -118,7 +118,7 @@ test2::__toString() Converted ====test7==== test2::__toString() -Illegal offset type +Illegal offset type: cannot be of type object ====test8==== test2::__toString() string(9) "Converted" From dba7099c8e72b1a53fac71c0f530f36bca143866 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 08:06:29 -0300 Subject: [PATCH 05/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/offset_array.phpt | 2 +- Zend/zend_execute.c | 22 +++---------- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 32 +++++++++---------- ext/opcache/tests/jit/assign_dim_002.phpt | 2 +- ext/opcache/tests/opt/inference_002.phpt | 4 +-- .../tests/array/array_key_exists.phpt | 2 +- 9 files changed, 29 insertions(+), 41 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 3d6e4746ed621..c0f1e6e52ba34 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type Closure diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index e55757bbcd417..c7fa7c1d1d481 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type Closure diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 47d7cc9f32e7e..60d2c1892a6b7 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -56,7 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type stdClass Illegal offset type: cannot be of type array Illegal offset type: cannot be of type array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 32bf0bc515d64..d9816f993b5b7 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1440,9 +1440,9 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(void) +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(const zval *offset) { - zend_type_error("Illegal offset type"); + zend_type_error("Illegal offset type: cannot be of type %s", zend_zval_type_name(offset)); } static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) @@ -2313,14 +2313,8 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval case IS_TRUE: value->lval = 1; return IS_LONG; - case IS_ARRAY: - zend_type_error("Illegal offset type: cannot be of type array"); - return IS_ARRAY; - case IS_OBJECT: - zend_type_error("Illegal offset type: cannot be of type object"); - return IS_OBJECT; default: - zend_illegal_offset(); + zend_illegal_offset(dim); return IS_NULL; } } @@ -2393,14 +2387,8 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv case IS_TRUE: value->lval = 1; return IS_LONG; - case IS_ARRAY: - zend_type_error("Illegal offset type: cannot be of type array"); - return IS_ARRAY; - case IS_OBJECT: - zend_type_error("Illegal offset type: cannot be of type object"); - return IS_OBJECT; default: - zend_illegal_offset(); + zend_illegal_offset(dim); return IS_NULL; } } @@ -2982,7 +2970,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_offset(); + zend_illegal_offset(key); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index a94f8cc762a80..d8b59788f9ac1 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6023,7 +6023,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 9813c62fdaa52..8cb122f671a2f 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7311,7 +7311,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -9508,7 +9508,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_T str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10431,7 +10431,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_U str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -11873,7 +11873,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -19845,7 +19845,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20285,7 +20285,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20746,7 +20746,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -21146,7 +21146,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -24882,7 +24882,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -27174,7 +27174,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -29195,7 +29195,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -31450,7 +31450,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -42795,7 +42795,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CONS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -46395,7 +46395,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_TMPV str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -48300,7 +48300,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_UNUS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -51788,7 +51788,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CV_H str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 4a03cc2641aca..b5343cf156b35 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type Closure array(1) { [0]=> array(2) { diff --git a/ext/opcache/tests/opt/inference_002.phpt b/ext/opcache/tests/opt/inference_002.phpt index 70412426c2fcc..93b0f205cac8e 100644 --- a/ext/opcache/tests/opt/inference_002.phpt +++ b/ext/opcache/tests/opt/inference_002.phpt @@ -9,7 +9,7 @@ opcache.optimization_level=-1 var_dump([[]=>&$x]); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %sinference_002.php:2 +Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %sinference_002.php:2 Stack trace: #0 {main} - thrown in %sinference_002.php on line 2 \ No newline at end of file + thrown in %sinference_002.php on line 2 diff --git a/ext/standard/tests/array/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt index d6f9ca13de718..9513895fbb1a5 100644 --- a/ext/standard/tests/array/array_key_exists.phpt +++ b/ext/standard/tests/array/array_key_exists.phpt @@ -202,7 +202,7 @@ bool(false) bool(true) *** Testing error conditions *** -Illegal offset type +Illegal offset type: cannot be of type array *** Testing operation on objects *** array_key_exists(): Argument #2 ($array) must be of type array, key_check given From 941632873c82cabebb0e7d494a3edf88b47f8923 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 11:22:08 -0300 Subject: [PATCH 06/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/init_array_illegal_offset_type.phpt | 2 +- Zend/tests/offset_array.phpt | 2 +- Zend/zend_execute.c | 2 +- ext/opcache/tests/jit/assign_dim_002.phpt | 2 +- ext/standard/tests/array/array_key_exists_variation1.phpt | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index c0f1e6e52ba34..3d6e4746ed621 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type Closure +Illegal offset type: cannot be of type object diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index c7fa7c1d1d481..697a634f3caa8 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type Closure +Illegal offset type: cannot be of type object diff --git a/Zend/tests/init_array_illegal_offset_type.phpt b/Zend/tests/init_array_illegal_offset_type.phpt index 2243ca2905ea0..e7f2f917bd0de 100644 --- a/Zend/tests/init_array_illegal_offset_type.phpt +++ b/Zend/tests/init_array_illegal_offset_type.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type object diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 60d2c1892a6b7..47d7cc9f32e7e 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -56,7 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type: cannot be of type stdClass +Illegal offset type: cannot be of type object Illegal offset type: cannot be of type array Illegal offset type: cannot be of type array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index d9816f993b5b7..1d3bdd29941e8 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1442,7 +1442,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(const zval *offset) { - zend_type_error("Illegal offset type: cannot be of type %s", zend_zval_type_name(offset)); + zend_type_error("Illegal offset type: cannot be of type %s", zend_get_type_by_const(Z_TYPE_P(offset))); } static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index b5343cf156b35..4a03cc2641aca 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type: cannot be of type Closure +Illegal offset type: cannot be of type object array(1) { [0]=> array(2) { diff --git a/ext/standard/tests/array/array_key_exists_variation1.phpt b/ext/standard/tests/array/array_key_exists_variation1.phpt index 3a410258bb999..c34896e2c78f0 100644 --- a/ext/standard/tests/array/array_key_exists_variation1.phpt +++ b/ext/standard/tests/array/array_key_exists_variation1.phpt @@ -129,7 +129,7 @@ bool(false) bool(false) -- Iteration 13 -- -Illegal offset type +Illegal offset type: cannot be of type array -- Iteration 14 -- bool(true) @@ -141,7 +141,7 @@ bool(true) bool(true) -- Iteration 17 -- -Illegal offset type +Illegal offset type: cannot be of type object -- Iteration 18 -- bool(false) From 821d8569fb7a81d75b9e169e563f1abde03471c9 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 07/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From f96b1aaafb32d57354bd93b322f2ac9e850dddd8 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 08/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From a8ad5c8c260ff668708bb4b4b1d6bea63ac6aa5d Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 09/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 45c755c5f6302c18f73117ff16e6226361652625 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 10/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 1173c2e64a52dc95dd9bd220393db5efc50ae6db Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 27 Jan 2023 19:32:25 +0100 Subject: [PATCH 11/92] Prevent dtor of generator in suspended fiber (#10462) Generators that suspended a fiber should not be dtor because they will be executed during the fiber dtor. Fiber dtor throws an exception in the fiber's context in order to unwind and execute finally blocks, which will also properly dtor the generator. Fixes GH-9916 --- Zend/tests/gh9916-001.phpt | 27 ++++++++++++++++++ Zend/tests/gh9916-002.phpt | 21 ++++++++++++++ Zend/tests/gh9916-003.phpt | 36 ++++++++++++++++++++++++ Zend/tests/gh9916-004.phpt | 26 +++++++++++++++++ Zend/tests/gh9916-005.phpt | 25 +++++++++++++++++ Zend/tests/gh9916-006.phpt | 37 +++++++++++++++++++++++++ Zend/tests/gh9916-007.phpt | 57 ++++++++++++++++++++++++++++++++++++++ Zend/tests/gh9916-008.phpt | 47 +++++++++++++++++++++++++++++++ Zend/tests/gh9916-009.phpt | 35 +++++++++++++++++++++++ Zend/tests/gh9916-010.phpt | 34 +++++++++++++++++++++++ Zend/tests/gh9916-011.phpt | 41 +++++++++++++++++++++++++++ Zend/zend_generators.c | 12 +++++++- Zend/zend_generators.h | 1 + 13 files changed, 398 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh9916-001.phpt create mode 100644 Zend/tests/gh9916-002.phpt create mode 100644 Zend/tests/gh9916-003.phpt create mode 100644 Zend/tests/gh9916-004.phpt create mode 100644 Zend/tests/gh9916-005.phpt create mode 100644 Zend/tests/gh9916-006.phpt create mode 100644 Zend/tests/gh9916-007.phpt create mode 100644 Zend/tests/gh9916-008.phpt create mode 100644 Zend/tests/gh9916-009.phpt create mode 100644 Zend/tests/gh9916-010.phpt create mode 100644 Zend/tests/gh9916-011.phpt diff --git a/Zend/tests/gh9916-001.phpt b/Zend/tests/gh9916-001.phpt new file mode 100644 index 0000000000000..3e518807238bc --- /dev/null +++ b/Zend/tests/gh9916-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally diff --git a/Zend/tests/gh9916-002.phpt b/Zend/tests/gh9916-002.phpt new file mode 100644 index 0000000000000..6f0b81cf3e91a --- /dev/null +++ b/Zend/tests/gh9916-002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-003.phpt b/Zend/tests/gh9916-003.phpt new file mode 100644 index 0000000000000..c4bfb815118bc --- /dev/null +++ b/Zend/tests/gh9916-003.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally (inner) +Finally diff --git a/Zend/tests/gh9916-004.phpt b/Zend/tests/gh9916-004.phpt new file mode 100644 index 0000000000000..1a51a841e8bb6 --- /dev/null +++ b/Zend/tests/gh9916-004.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-005.phpt b/Zend/tests/gh9916-005.phpt new file mode 100644 index 0000000000000..f84c756919cd0 --- /dev/null +++ b/Zend/tests/gh9916-005.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +send($fiber); + $gen->current(); +}); +$fiber->start(); + +$gen = null; +$fiber = null; +gc_collect_cycles(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-006.phpt b/Zend/tests/gh9916-006.phpt new file mode 100644 index 0000000000000..28c57105c7b1f --- /dev/null +++ b/Zend/tests/gh9916-006.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Fiber return\n"; +}); +$fiber->start(); +$fiber->resume(); +$gen->next(); +$gen->current(); +?> +==DONE== +--EXPECT-- +Before suspend +After suspend +Fiber return +Before exit diff --git a/Zend/tests/gh9916-007.phpt b/Zend/tests/gh9916-007.phpt new file mode 100644 index 0000000000000..e1ec3fb19f32b --- /dev/null +++ b/Zend/tests/gh9916-007.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally (iterator) +Finally diff --git a/Zend/tests/gh9916-008.phpt b/Zend/tests/gh9916-008.phpt new file mode 100644 index 0000000000000..84521d69e2120 --- /dev/null +++ b/Zend/tests/gh9916-008.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-009.phpt b/Zend/tests/gh9916-009.phpt new file mode 100644 index 0000000000000..75643d871dea0 --- /dev/null +++ b/Zend/tests/gh9916-009.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- + new stdClass]; + print "Not executed\n"; + } +})(); +$fiber = new Fiber(function() use ($gen, &$fiber) { + $gen->current(); + print "Not executed\n"; +}); +$fiber->start(); +?> +==DONE== +--EXPECTF-- +Before suspend +==DONE== +Finally + +Fatal error: Uncaught Error: Cannot use "yield from" in a force-closed generator in %s:%d +Stack trace: +#0 [internal function]: {closure}() +#1 %s(%d): Generator->current() +#2 [internal function]: {closure}() +#3 {main} + thrown in %s on line %d diff --git a/Zend/tests/gh9916-010.phpt b/Zend/tests/gh9916-010.phpt new file mode 100644 index 0000000000000..d3a841d7ceb31 --- /dev/null +++ b/Zend/tests/gh9916-010.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Before next\n"; + $gen->next(); + print "Not executed\n"; +}); + +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before current +Before yield +Before yield 2 +Before next +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-011.phpt b/Zend/tests/gh9916-011.phpt new file mode 100644 index 0000000000000..05fa884c29337 --- /dev/null +++ b/Zend/tests/gh9916-011.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +next(); + } +})(); + +$fiber = new Fiber(function () use ($gen, &$fiber) { + print "Before current\n"; + $gen->current(); + print "Before next\n"; + $gen->next(); + print "Not executed\n"; +}); + +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before current +Before yield +Before yield 2 +Before next +Before suspend +==DONE== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index d5253e46eddf2..24316dc4e896b 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -223,6 +223,14 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */ uint32_t op_num, try_catch_offset; int i; + /* Generator is running in a suspended fiber. + * Will be dtor during fiber dtor */ + if (generator->flags & ZEND_GENERATOR_IN_FIBER) { + /* Prevent finally blocks from yielding */ + generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; + return; + } + /* leave yield from mode to properly allow finally execution */ if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { zval_ptr_dtor(&generator->values); @@ -727,7 +735,8 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ } /* Resume execution */ - generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING; + generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING + | (EG(active_fiber) ? ZEND_GENERATOR_IN_FIBER : 0); if (!ZEND_OBSERVER_ENABLED) { zend_execute_ex(generator->execute_data); } else { @@ -778,6 +787,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ goto try_again; } + generator->flags &= ~ZEND_GENERATOR_IN_FIBER; orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT; } /* }}} */ diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h index 17b25a99b87c1..4ccc42b92f668 100644 --- a/Zend/zend_generators.h +++ b/Zend/zend_generators.h @@ -92,6 +92,7 @@ static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1; static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2; static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4; static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8; +static const zend_uchar ZEND_GENERATOR_IN_FIBER = 0x10; void zend_register_generator_ce(void); ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution); From d7de73b551a2499290c2b8afe1d899d00432b706 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:33:58 +0100 Subject: [PATCH 12/92] Fix overflow check in OnUpdateMemoryConsumption (#10456) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit memsize is a signed long, therefore the check against the (*un*signed long maximum) / 1024² will allow too large values. This check worked correctly in d4b3f89c53f8 where it checked against the maximum signed value, but was broken in 003346c450b5. Fix it by changing ZEND_ULONG_MAX to ZEND_LONG_MAX. --- ext/opcache/zend_accelerator_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index da1696bb92083..2300ee2964bea 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -70,8 +70,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption) zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption is set below the required 8MB.\n"); return FAILURE; } - if (UNEXPECTED(memsize > ZEND_ULONG_MAX / (1024 * 1024))) { - *p = ZEND_ULONG_MAX; + if (UNEXPECTED(memsize > ZEND_LONG_MAX / (1024 * 1024))) { + *p = ZEND_LONG_MAX; } else { *p = memsize * (1024 * 1024); } From a24ac59e553c0df88bb6acd8f53a4ff8fb944139 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 27 Jan 2023 19:36:28 +0100 Subject: [PATCH 13/92] [ci skip] NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index d8028bf92a63c..411201c1acca1 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ PHP NEWS - Core: . Fixed incorrect check condition in ZEND_YIELD. (nielsdos) . Fixed incorrect check condition in type inference. (nielsdos) + . Fixed overflow check in OnUpdateMemoryConsumption. (nielsdos) + . Fixed bug GH-9916 (Entering shutdown sequence with a fiber suspended in a + Generator emits an unavoidable fatal error or crashes). (Arnaud) - FFI: . Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos) From cfb6e82cbd1e00d8271c05b9a78ce3fc1acb68f7 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 27 Jan 2023 19:37:27 +0100 Subject: [PATCH 14/92] [ci skip] NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index b1abfcaf440f0..5594fb3855dd9 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ PHP NEWS . Fixed incorrect check condition in ZEND_YIELD. (nielsdos) . Fixed incorrect check condition in type inference. (nielsdos) . Fix incorrect check in zend_internal_call_should_throw(). (nielsdos) + . Fixed overflow check in OnUpdateMemoryConsumption. (nielsdos) + . Fixed bug GH-9916 (Entering shutdown sequence with a fiber suspended in a + Generator emits an unavoidable fatal error or crashes). (Arnaud) - FFI: . Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos) From aeca4d222bd241e9cfd5e24a0d35a256b904e11f Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 27 Jan 2023 19:32:25 +0100 Subject: [PATCH 15/92] Prevent dtor of generator in suspended fiber (#10462) Generators that suspended a fiber should not be dtor because they will be executed during the fiber dtor. Fiber dtor throws an exception in the fiber's context in order to unwind and execute finally blocks, which will also properly dtor the generator. Fixes GH-9916 --- Zend/tests/gh9916-001.phpt | 27 ++++++++++++++++++ Zend/tests/gh9916-002.phpt | 21 ++++++++++++++ Zend/tests/gh9916-003.phpt | 36 ++++++++++++++++++++++++ Zend/tests/gh9916-004.phpt | 26 +++++++++++++++++ Zend/tests/gh9916-005.phpt | 25 +++++++++++++++++ Zend/tests/gh9916-006.phpt | 37 +++++++++++++++++++++++++ Zend/tests/gh9916-007.phpt | 57 ++++++++++++++++++++++++++++++++++++++ Zend/tests/gh9916-008.phpt | 47 +++++++++++++++++++++++++++++++ Zend/tests/gh9916-009.phpt | 35 +++++++++++++++++++++++ Zend/tests/gh9916-010.phpt | 34 +++++++++++++++++++++++ Zend/tests/gh9916-011.phpt | 41 +++++++++++++++++++++++++++ Zend/zend_generators.c | 12 +++++++- Zend/zend_generators.h | 1 + 13 files changed, 398 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/gh9916-001.phpt create mode 100644 Zend/tests/gh9916-002.phpt create mode 100644 Zend/tests/gh9916-003.phpt create mode 100644 Zend/tests/gh9916-004.phpt create mode 100644 Zend/tests/gh9916-005.phpt create mode 100644 Zend/tests/gh9916-006.phpt create mode 100644 Zend/tests/gh9916-007.phpt create mode 100644 Zend/tests/gh9916-008.phpt create mode 100644 Zend/tests/gh9916-009.phpt create mode 100644 Zend/tests/gh9916-010.phpt create mode 100644 Zend/tests/gh9916-011.phpt diff --git a/Zend/tests/gh9916-001.phpt b/Zend/tests/gh9916-001.phpt new file mode 100644 index 0000000000000..3e518807238bc --- /dev/null +++ b/Zend/tests/gh9916-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally diff --git a/Zend/tests/gh9916-002.phpt b/Zend/tests/gh9916-002.phpt new file mode 100644 index 0000000000000..6f0b81cf3e91a --- /dev/null +++ b/Zend/tests/gh9916-002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-003.phpt b/Zend/tests/gh9916-003.phpt new file mode 100644 index 0000000000000..c4bfb815118bc --- /dev/null +++ b/Zend/tests/gh9916-003.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally (inner) +Finally diff --git a/Zend/tests/gh9916-004.phpt b/Zend/tests/gh9916-004.phpt new file mode 100644 index 0000000000000..1a51a841e8bb6 --- /dev/null +++ b/Zend/tests/gh9916-004.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-005.phpt b/Zend/tests/gh9916-005.phpt new file mode 100644 index 0000000000000..f84c756919cd0 --- /dev/null +++ b/Zend/tests/gh9916-005.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +send($fiber); + $gen->current(); +}); +$fiber->start(); + +$gen = null; +$fiber = null; +gc_collect_cycles(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-006.phpt b/Zend/tests/gh9916-006.phpt new file mode 100644 index 0000000000000..28c57105c7b1f --- /dev/null +++ b/Zend/tests/gh9916-006.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Fiber return\n"; +}); +$fiber->start(); +$fiber->resume(); +$gen->next(); +$gen->current(); +?> +==DONE== +--EXPECT-- +Before suspend +After suspend +Fiber return +Before exit diff --git a/Zend/tests/gh9916-007.phpt b/Zend/tests/gh9916-007.phpt new file mode 100644 index 0000000000000..e1ec3fb19f32b --- /dev/null +++ b/Zend/tests/gh9916-007.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally (iterator) +Finally diff --git a/Zend/tests/gh9916-008.phpt b/Zend/tests/gh9916-008.phpt new file mode 100644 index 0000000000000..84521d69e2120 --- /dev/null +++ b/Zend/tests/gh9916-008.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-009.phpt b/Zend/tests/gh9916-009.phpt new file mode 100644 index 0000000000000..75643d871dea0 --- /dev/null +++ b/Zend/tests/gh9916-009.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- + new stdClass]; + print "Not executed\n"; + } +})(); +$fiber = new Fiber(function() use ($gen, &$fiber) { + $gen->current(); + print "Not executed\n"; +}); +$fiber->start(); +?> +==DONE== +--EXPECTF-- +Before suspend +==DONE== +Finally + +Fatal error: Uncaught Error: Cannot use "yield from" in a force-closed generator in %s:%d +Stack trace: +#0 [internal function]: {closure}() +#1 %s(%d): Generator->current() +#2 [internal function]: {closure}() +#3 {main} + thrown in %s on line %d diff --git a/Zend/tests/gh9916-010.phpt b/Zend/tests/gh9916-010.phpt new file mode 100644 index 0000000000000..d3a841d7ceb31 --- /dev/null +++ b/Zend/tests/gh9916-010.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Before next\n"; + $gen->next(); + print "Not executed\n"; +}); + +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before current +Before yield +Before yield 2 +Before next +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-011.phpt b/Zend/tests/gh9916-011.phpt new file mode 100644 index 0000000000000..05fa884c29337 --- /dev/null +++ b/Zend/tests/gh9916-011.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +next(); + } +})(); + +$fiber = new Fiber(function () use ($gen, &$fiber) { + print "Before current\n"; + $gen->current(); + print "Before next\n"; + $gen->next(); + print "Not executed\n"; +}); + +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before current +Before yield +Before yield 2 +Before next +Before suspend +==DONE== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index fb1e2e6d52a73..6997d95af0390 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -223,6 +223,14 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */ uint32_t op_num, try_catch_offset; int i; + /* Generator is running in a suspended fiber. + * Will be dtor during fiber dtor */ + if (generator->flags & ZEND_GENERATOR_IN_FIBER) { + /* Prevent finally blocks from yielding */ + generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; + return; + } + /* leave yield from mode to properly allow finally execution */ if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { zval_ptr_dtor(&generator->values); @@ -741,7 +749,8 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ } /* Resume execution */ - generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING; + generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING + | (EG(active_fiber) ? ZEND_GENERATOR_IN_FIBER : 0); if (!ZEND_OBSERVER_ENABLED) { zend_execute_ex(generator->execute_data); } else { @@ -792,6 +801,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ goto try_again; } + generator->flags &= ~ZEND_GENERATOR_IN_FIBER; orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT; } /* }}} */ diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h index 17b25a99b87c1..4ccc42b92f668 100644 --- a/Zend/zend_generators.h +++ b/Zend/zend_generators.h @@ -92,6 +92,7 @@ static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1; static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2; static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4; static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8; +static const zend_uchar ZEND_GENERATOR_IN_FIBER = 0x10; void zend_register_generator_ce(void); ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution); From 63cac9520a6126e141838371f5fbcae9683d067c Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:33:58 +0100 Subject: [PATCH 16/92] Fix overflow check in OnUpdateMemoryConsumption (#10456) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit memsize is a signed long, therefore the check against the (*un*signed long maximum) / 1024² will allow too large values. This check worked correctly in d4b3f89c53f8 where it checked against the maximum signed value, but was broken in 003346c450b5. Fix it by changing ZEND_ULONG_MAX to ZEND_LONG_MAX. --- ext/opcache/zend_accelerator_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 2eb0b38a7a38b..45a39da7da535 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -72,8 +72,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption) zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption is set below the required 8MB.\n"); return FAILURE; } - if (UNEXPECTED(memsize > ZEND_ULONG_MAX / (1024 * 1024))) { - *p = ZEND_ULONG_MAX; + if (UNEXPECTED(memsize > ZEND_LONG_MAX / (1024 * 1024))) { + *p = ZEND_LONG_MAX; } else { *p = memsize * (1024 * 1024); } From be68ced96bef2cb9124acd689e09b1bd6a01e278 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 17/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 2e1d1f0e6463212cbb2abac96cb6510a0310de97 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 18/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From f9e5a1746f618ca07c9ea31a725214c835606bfb Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 19/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 4b812e4e03f92a9fd57fed18be8721c9ef340af2 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 20/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 1d4b18e376742d7df87631bc148d0e2d29ca19d9 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 16:54:14 -0300 Subject: [PATCH 21/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/assign_dim_obj_null_return.phpt | 8 ++--- Zend/tests/bug79790.phpt | 2 +- Zend/tests/bug79947.phpt | 2 +- .../tests/init_array_illegal_offset_type.phpt | 2 +- Zend/tests/offset_array.phpt | 6 ++-- Zend/zend_execute.c | 10 +++--- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 32 +++++++++---------- ext/opcache/tests/jit/assign_dim_002.phpt | 6 ++-- ext/opcache/tests/jit/assign_dim_op_001.phpt | 4 +-- ext/opcache/tests/jit/fetch_dim_rw_004.phpt | 2 +- ext/opcache/tests/opt/inference_002.phpt | 2 +- .../tests/array/array_key_exists.phpt | 2 +- .../array/array_key_exists_variation1.phpt | 4 +-- tests/classes/tostring_001.phpt | 2 +- 17 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 3d6e4746ed621..4037d3d0e3d21 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index 697a634f3caa8..4f822a6f5a154 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array diff --git a/Zend/tests/assign_dim_obj_null_return.phpt b/Zend/tests/assign_dim_obj_null_return.phpt index b2e56ed04528a..02e709818669e 100644 --- a/Zend/tests/assign_dim_obj_null_return.phpt +++ b/Zend/tests/assign_dim_obj_null_return.phpt @@ -72,12 +72,12 @@ test(); ?> --EXPECT-- Cannot add element to the array as the next element is already occupied -Illegal offset type: cannot be of type array -Illegal offset type: cannot be of type object +Cannot access offset of type array on array +Cannot access offset of type object on array Cannot use a scalar value as an array Cannot add element to the array as the next element is already occupied -Illegal offset type: cannot be of type array -Illegal offset type: cannot be of type object +Cannot access offset of type array on array +Cannot access offset of type object on array Cannot use a scalar value as an array Attempt to assign property "foo" on true Attempt to assign property "foo" on true diff --git a/Zend/tests/bug79790.phpt b/Zend/tests/bug79790.phpt index 125f74aedc339..0d34e2be0fc1e 100644 --- a/Zend/tests/bug79790.phpt +++ b/Zend/tests/bug79790.phpt @@ -8,7 +8,7 @@ function b($a = array()[array ()]) { } ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %s:%d Stack trace: #0 %s(%d): b() #1 {main} diff --git a/Zend/tests/bug79947.phpt b/Zend/tests/bug79947.phpt index edfbdaa0b754c..0593eacfd6c48 100644 --- a/Zend/tests/bug79947.phpt +++ b/Zend/tests/bug79947.phpt @@ -12,6 +12,6 @@ try { var_dump($array); ?> --EXPECT-- -Illegal offset type: cannot be of type array +Cannot access offset of type array on array array(0) { } diff --git a/Zend/tests/init_array_illegal_offset_type.phpt b/Zend/tests/init_array_illegal_offset_type.phpt index e7f2f917bd0de..2e5a0401d6e4a 100644 --- a/Zend/tests/init_array_illegal_offset_type.phpt +++ b/Zend/tests/init_array_illegal_offset_type.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 47d7cc9f32e7e..c526beca91a89 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -56,7 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type: cannot be of type object -Illegal offset type: cannot be of type array -Illegal offset type: cannot be of type array +Cannot access offset of type object on array +Cannot access offset of type array on array +Cannot access offset of type array on array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 0bc344760382a..bb79f6de8aeca 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,9 +1455,9 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(const zval *offset) +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset) { - zend_type_error("Illegal offset type: cannot be of type %s", zend_get_type_by_const(Z_TYPE_P(offset))); + zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) @@ -2329,7 +2329,7 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval value->lval = 1; return IS_LONG; default: - zend_illegal_offset(dim); + zend_illegal_array_offset(dim); return IS_NULL; } } @@ -2403,7 +2403,7 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv value->lval = 1; return IS_LONG; default: - zend_illegal_offset(dim); + zend_illegal_array_offset(dim); return IS_NULL; } } @@ -2985,7 +2985,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_offset(key); + zend_illegal_array_offset(key); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 09dfe0426e4de..6c07924e99cd1 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6055,7 +6055,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 1cf9ff76a8d9c..8eb981c07063d 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7342,7 +7342,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -9655,7 +9655,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_T str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10578,7 +10578,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_U str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -12020,7 +12020,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -19992,7 +19992,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20432,7 +20432,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20893,7 +20893,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -21293,7 +21293,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25060,7 +25060,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -27468,7 +27468,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -29489,7 +29489,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -31744,7 +31744,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -43236,7 +43236,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CONS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -46836,7 +46836,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_TMPV str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -48741,7 +48741,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_UNUS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52229,7 +52229,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CV_H str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 4a03cc2641aca..83b4bfdec7873 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type: cannot be of type object +Cannot access offset of type object on array array(1) { [0]=> array(2) { @@ -198,7 +198,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d int(1) @@ -221,7 +221,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Warning: Undefined variable $undef in %s on line %d NULL diff --git a/ext/opcache/tests/jit/assign_dim_op_001.phpt b/ext/opcache/tests/jit/assign_dim_op_001.phpt index f63a5de66938b..731a2e96420a7 100644 --- a/ext/opcache/tests/jit/assign_dim_op_001.phpt +++ b/ext/opcache/tests/jit/assign_dim_op_001.phpt @@ -79,7 +79,7 @@ Warning: Undefined array key 2 in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d @@ -104,5 +104,5 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Unsupported operand types: null % string diff --git a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt index 65ad0e0d5a06a..d9302b8fd04ce 100644 --- a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt +++ b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt @@ -18,7 +18,7 @@ Stack trace: #0 %sfetch_dim_rw_004.php(5): {closure}(2, 'Undefined varia...', '%s', 5) #1 {main} -Next TypeError: Illegal offset type: cannot be of type array in %sfetch_dim_rw_004.php:5 +Next TypeError: Cannot access offset of type array on array in %sfetch_dim_rw_004.php:5 Stack trace: #0 {main} thrown in %sfetch_dim_rw_004.php on line 5 diff --git a/ext/opcache/tests/opt/inference_002.phpt b/ext/opcache/tests/opt/inference_002.phpt index 93b0f205cac8e..3d8c69d054e5d 100644 --- a/ext/opcache/tests/opt/inference_002.phpt +++ b/ext/opcache/tests/opt/inference_002.phpt @@ -9,7 +9,7 @@ opcache.optimization_level=-1 var_dump([[]=>&$x]); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %sinference_002.php:2 +Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %sinference_002.php:2 Stack trace: #0 {main} thrown in %sinference_002.php on line 2 diff --git a/ext/standard/tests/array/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt index 9513895fbb1a5..8cc2f9c5207c2 100644 --- a/ext/standard/tests/array/array_key_exists.phpt +++ b/ext/standard/tests/array/array_key_exists.phpt @@ -202,7 +202,7 @@ bool(false) bool(true) *** Testing error conditions *** -Illegal offset type: cannot be of type array +Cannot access offset of type array on array *** Testing operation on objects *** array_key_exists(): Argument #2 ($array) must be of type array, key_check given diff --git a/ext/standard/tests/array/array_key_exists_variation1.phpt b/ext/standard/tests/array/array_key_exists_variation1.phpt index c34896e2c78f0..eb35d1bfae0c1 100644 --- a/ext/standard/tests/array/array_key_exists_variation1.phpt +++ b/ext/standard/tests/array/array_key_exists_variation1.phpt @@ -129,7 +129,7 @@ bool(false) bool(false) -- Iteration 13 -- -Illegal offset type: cannot be of type array +Cannot access offset of type array on array -- Iteration 14 -- bool(true) @@ -141,7 +141,7 @@ bool(true) bool(true) -- Iteration 17 -- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array -- Iteration 18 -- bool(false) diff --git a/tests/classes/tostring_001.phpt b/tests/classes/tostring_001.phpt index df54e08a002cf..ddbe4d152dde0 100644 --- a/tests/classes/tostring_001.phpt +++ b/tests/classes/tostring_001.phpt @@ -118,7 +118,7 @@ test2::__toString() Converted ====test7==== test2::__toString() -Illegal offset type: cannot be of type object +Cannot access offset of type object on array ====test8==== test2::__toString() string(9) "Converted" From adf0d4fce18d8b04d13a9f7b79731ccdbbd0da21 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:09:27 -0300 Subject: [PATCH 22/92] Revert "Fix overflow check in OnUpdateMemoryConsumption (#10456)" This reverts commit 63cac9520a6126e141838371f5fbcae9683d067c. --- ext/opcache/zend_accelerator_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 45a39da7da535..2eb0b38a7a38b 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -72,8 +72,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption) zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption is set below the required 8MB.\n"); return FAILURE; } - if (UNEXPECTED(memsize > ZEND_LONG_MAX / (1024 * 1024))) { - *p = ZEND_LONG_MAX; + if (UNEXPECTED(memsize > ZEND_ULONG_MAX / (1024 * 1024))) { + *p = ZEND_ULONG_MAX; } else { *p = memsize * (1024 * 1024); } From 4e3808b942caf86627bee377843235c4c4bd8288 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:09:36 -0300 Subject: [PATCH 23/92] Revert "Prevent dtor of generator in suspended fiber (#10462)" This reverts commit aeca4d222bd241e9cfd5e24a0d35a256b904e11f. --- Zend/tests/gh9916-001.phpt | 27 ------------------ Zend/tests/gh9916-002.phpt | 21 -------------- Zend/tests/gh9916-003.phpt | 36 ------------------------ Zend/tests/gh9916-004.phpt | 26 ----------------- Zend/tests/gh9916-005.phpt | 25 ----------------- Zend/tests/gh9916-006.phpt | 37 ------------------------- Zend/tests/gh9916-007.phpt | 57 -------------------------------------- Zend/tests/gh9916-008.phpt | 47 ------------------------------- Zend/tests/gh9916-009.phpt | 35 ----------------------- Zend/tests/gh9916-010.phpt | 34 ----------------------- Zend/tests/gh9916-011.phpt | 41 --------------------------- Zend/zend_generators.c | 12 +------- Zend/zend_generators.h | 1 - 13 files changed, 1 insertion(+), 398 deletions(-) delete mode 100644 Zend/tests/gh9916-001.phpt delete mode 100644 Zend/tests/gh9916-002.phpt delete mode 100644 Zend/tests/gh9916-003.phpt delete mode 100644 Zend/tests/gh9916-004.phpt delete mode 100644 Zend/tests/gh9916-005.phpt delete mode 100644 Zend/tests/gh9916-006.phpt delete mode 100644 Zend/tests/gh9916-007.phpt delete mode 100644 Zend/tests/gh9916-008.phpt delete mode 100644 Zend/tests/gh9916-009.phpt delete mode 100644 Zend/tests/gh9916-010.phpt delete mode 100644 Zend/tests/gh9916-011.phpt diff --git a/Zend/tests/gh9916-001.phpt b/Zend/tests/gh9916-001.phpt deleted file mode 100644 index 3e518807238bc..0000000000000 --- a/Zend/tests/gh9916-001.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally diff --git a/Zend/tests/gh9916-002.phpt b/Zend/tests/gh9916-002.phpt deleted file mode 100644 index 6f0b81cf3e91a..0000000000000 --- a/Zend/tests/gh9916-002.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-003.phpt b/Zend/tests/gh9916-003.phpt deleted file mode 100644 index c4bfb815118bc..0000000000000 --- a/Zend/tests/gh9916-003.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally (inner) -Finally diff --git a/Zend/tests/gh9916-004.phpt b/Zend/tests/gh9916-004.phpt deleted file mode 100644 index 1a51a841e8bb6..0000000000000 --- a/Zend/tests/gh9916-004.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-005.phpt b/Zend/tests/gh9916-005.phpt deleted file mode 100644 index f84c756919cd0..0000000000000 --- a/Zend/tests/gh9916-005.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -send($fiber); - $gen->current(); -}); -$fiber->start(); - -$gen = null; -$fiber = null; -gc_collect_cycles(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-006.phpt b/Zend/tests/gh9916-006.phpt deleted file mode 100644 index 28c57105c7b1f..0000000000000 --- a/Zend/tests/gh9916-006.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Fiber return\n"; -}); -$fiber->start(); -$fiber->resume(); -$gen->next(); -$gen->current(); -?> -==DONE== ---EXPECT-- -Before suspend -After suspend -Fiber return -Before exit diff --git a/Zend/tests/gh9916-007.phpt b/Zend/tests/gh9916-007.phpt deleted file mode 100644 index e1ec3fb19f32b..0000000000000 --- a/Zend/tests/gh9916-007.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally (iterator) -Finally diff --git a/Zend/tests/gh9916-008.phpt b/Zend/tests/gh9916-008.phpt deleted file mode 100644 index 84521d69e2120..0000000000000 --- a/Zend/tests/gh9916-008.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-009.phpt b/Zend/tests/gh9916-009.phpt deleted file mode 100644 index 75643d871dea0..0000000000000 --- a/Zend/tests/gh9916-009.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- - new stdClass]; - print "Not executed\n"; - } -})(); -$fiber = new Fiber(function() use ($gen, &$fiber) { - $gen->current(); - print "Not executed\n"; -}); -$fiber->start(); -?> -==DONE== ---EXPECTF-- -Before suspend -==DONE== -Finally - -Fatal error: Uncaught Error: Cannot use "yield from" in a force-closed generator in %s:%d -Stack trace: -#0 [internal function]: {closure}() -#1 %s(%d): Generator->current() -#2 [internal function]: {closure}() -#3 {main} - thrown in %s on line %d diff --git a/Zend/tests/gh9916-010.phpt b/Zend/tests/gh9916-010.phpt deleted file mode 100644 index d3a841d7ceb31..0000000000000 --- a/Zend/tests/gh9916-010.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Before next\n"; - $gen->next(); - print "Not executed\n"; -}); - -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before current -Before yield -Before yield 2 -Before next -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-011.phpt b/Zend/tests/gh9916-011.phpt deleted file mode 100644 index 05fa884c29337..0000000000000 --- a/Zend/tests/gh9916-011.phpt +++ /dev/null @@ -1,41 +0,0 @@ ---TEST-- -Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -next(); - } -})(); - -$fiber = new Fiber(function () use ($gen, &$fiber) { - print "Before current\n"; - $gen->current(); - print "Before next\n"; - $gen->next(); - print "Not executed\n"; -}); - -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before current -Before yield -Before yield 2 -Before next -Before suspend -==DONE== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 6997d95af0390..fb1e2e6d52a73 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -223,14 +223,6 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */ uint32_t op_num, try_catch_offset; int i; - /* Generator is running in a suspended fiber. - * Will be dtor during fiber dtor */ - if (generator->flags & ZEND_GENERATOR_IN_FIBER) { - /* Prevent finally blocks from yielding */ - generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; - return; - } - /* leave yield from mode to properly allow finally execution */ if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { zval_ptr_dtor(&generator->values); @@ -749,8 +741,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ } /* Resume execution */ - generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING - | (EG(active_fiber) ? ZEND_GENERATOR_IN_FIBER : 0); + generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING; if (!ZEND_OBSERVER_ENABLED) { zend_execute_ex(generator->execute_data); } else { @@ -801,7 +792,6 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ goto try_again; } - generator->flags &= ~ZEND_GENERATOR_IN_FIBER; orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT; } /* }}} */ diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h index 4ccc42b92f668..17b25a99b87c1 100644 --- a/Zend/zend_generators.h +++ b/Zend/zend_generators.h @@ -92,7 +92,6 @@ static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1; static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2; static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4; static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8; -static const zend_uchar ZEND_GENERATOR_IN_FIBER = 0x10; void zend_register_generator_ce(void); ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution); From e789645e9fb31ce1415c60438421c078734908bf Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:44:48 -0300 Subject: [PATCH 24/92] fix: handle JIT helper. --- ext/opcache/jit/zend_jit_helpers.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index c594ade575bed..d2285cafac370 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,9 +27,9 @@ static ZEND_COLD void undef_result_after_exception(void) { } } -static ZEND_COLD void zend_jit_illegal_offset(void) +static ZEND_COLD void zend_jit_illegal_offset(zval *offset) { - zend_type_error("Illegal offset type"); + zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } static ZEND_COLD void zend_jit_illegal_string_offset(zval *offset) @@ -488,7 +488,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return; } @@ -630,7 +630,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return; } @@ -868,7 +868,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return NULL; } @@ -1001,7 +1001,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From dc6fbec037951cff2532c44005ecd38db55cfad7 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 28 Jan 2023 11:48:46 +0100 Subject: [PATCH 25/92] Fix missing zend_shared_alloc_unlock() (#10405) This code was refactored and the unlock was forgotten. The following assertion is triggered in debug mode: zend_shared_alloc_lock: Assertion `!(accel_globals.locked)' failed. And in release mode this likely deadlocks. Fix this by re-adding the unlock. --- ext/opcache/ZendAccelerator.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index a7f9431a06cfd..0d589c7c61d0f 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -4788,6 +4788,7 @@ static int accel_finish_startup(void) } if (pid == -1) { /* no subprocess was needed */ + /* The called function unlocks the shared alloc lock */ return accel_finish_startup_preload(false); } else if (pid == 0) { /* subprocess */ int ret = accel_finish_startup_preload(true); @@ -4805,6 +4806,8 @@ static int accel_finish_startup(void) preload_load(); } + zend_shared_alloc_unlock(); + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { return SUCCESS; } else { From 306a72add490a09bdbd0c73682c053be785b3ca7 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Sat, 28 Jan 2023 11:49:14 +0100 Subject: [PATCH 26/92] Add test for GH-10405 --- ext/opcache/tests/gh10405.inc | 2 ++ ext/opcache/tests/gh10405.phpt | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ext/opcache/tests/gh10405.inc create mode 100644 ext/opcache/tests/gh10405.phpt diff --git a/ext/opcache/tests/gh10405.inc b/ext/opcache/tests/gh10405.inc new file mode 100644 index 0000000000000..cd6cb00097caa --- /dev/null +++ b/ext/opcache/tests/gh10405.inc @@ -0,0 +1,2 @@ + +--FILE-- + +OK +--EXPECTF-- +bool(false) +included +OK From d5e4ec4b6ca0cbfa8eaae4fba70d639ab66168fd Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Sat, 28 Jan 2023 09:24:23 -0300 Subject: [PATCH 27/92] fix: also treat isset and empty --- Zend/tests/bug80781.phpt | 2 +- ...nstant_expressions_invalid_offset_type_error.phpt | 2 +- Zend/tests/illegal_offset_unset_isset_empty.phpt | 6 +++--- Zend/tests/isset_array.phpt | 4 ++-- Zend/zend_API.c | 7 ++++++- Zend/zend_execute.c | 12 +++++++++++- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 12 ++++++------ ext/opcache/jit/zend_jit_helpers.c | 7 ++++++- ext/spl/tests/iterator_to_array_nonscalar_keys.phpt | 2 +- ext/standard/tests/array/bug68553.phpt | 4 ++-- 11 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Zend/tests/bug80781.phpt b/Zend/tests/bug80781.phpt index eb5109add9f6c..0dc004fb9d74c 100644 --- a/Zend/tests/bug80781.phpt +++ b/Zend/tests/bug80781.phpt @@ -25,7 +25,7 @@ if (isset($array[$data]) or getPlugin($data)) { ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type array in isset or empty in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/constant_expressions_invalid_offset_type_error.phpt b/Zend/tests/constant_expressions_invalid_offset_type_error.phpt index 649c3a325a0c2..1a0ef52dce082 100644 --- a/Zend/tests/constant_expressions_invalid_offset_type_error.phpt +++ b/Zend/tests/constant_expressions_invalid_offset_type_error.phpt @@ -8,7 +8,7 @@ const C2 = [C1, [] => 1]; ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/illegal_offset_unset_isset_empty.phpt b/Zend/tests/illegal_offset_unset_isset_empty.phpt index 9005053e67ed8..9e5818136445d 100644 --- a/Zend/tests/illegal_offset_unset_isset_empty.phpt +++ b/Zend/tests/illegal_offset_unset_isset_empty.phpt @@ -22,6 +22,6 @@ try { ?> --EXPECT-- -Illegal offset type in unset -Illegal offset type in isset or empty -Illegal offset type in isset or empty +Cannot access offset of type array on unset +Cannot access offset of type array in isset or empty +Cannot access offset of type array in isset or empty diff --git a/Zend/tests/isset_array.phpt b/Zend/tests/isset_array.phpt index 4a0652ae39d5f..792483294805d 100644 --- a/Zend/tests/isset_array.phpt +++ b/Zend/tests/isset_array.phpt @@ -46,5 +46,5 @@ bool(false) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(false) -Illegal offset type in isset or empty -Illegal offset type in isset or empty +Cannot access offset of type array in isset or empty +Cannot access offset of type object in isset or empty diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 21e768f0947c3..ba6f801e24c49 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2046,6 +2046,11 @@ ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref) /* } /* }}} */ +ZEND_API void zend_illegal_array_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); +} + ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */ { zval *result; @@ -2074,7 +2079,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) / result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value); break; default: - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(key); result = NULL; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index bb79f6de8aeca..21314face6c2d 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,6 +1455,16 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_empty_or_isset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); +} + +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_unset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s on unset", zend_get_type_by_const(Z_TYPE_P(offset))); +} + static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); @@ -2862,7 +2872,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable ZVAL_UNDEFINED_OP2(); goto str_idx; } else { - zend_type_error("Illegal offset type in isset or empty"); + zend_illegal_empty_or_isset_offset(offset); return NULL; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 6c07924e99cd1..4b7902be7675a 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6571,7 +6571,7 @@ ZEND_VM_C_LABEL(num_index_dim): key = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index_dim); } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 8eb981c07063d..585b9ec6df141 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -25152,7 +25152,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_CONST_HANDL key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -27560,7 +27560,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_TMPVAR_HAND key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -31836,7 +31836,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_CV_HANDLER( key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -43328,7 +43328,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_CONST_HANDLE key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -46928,7 +46928,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_TMPVAR_HANDL key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -52321,7 +52321,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_CV_HANDLER(Z key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index d2285cafac370..63280ad09aab0 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,6 +27,11 @@ static ZEND_COLD void undef_result_after_exception(void) { } } +static ZEND_COLD void zend_jit_illegal_empty_or_isset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); +} + static ZEND_COLD void zend_jit_illegal_offset(zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); @@ -732,7 +737,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d hval = 1; goto num_index; default: - zend_type_error("Illegal offset type in isset or empty"); + zend_jit_illegal_empty_or_isset_offset(dim); return 0; } diff --git a/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt index f3460bfccca77..44b4e2a0ebcbb 100644 --- a/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt +++ b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt @@ -21,4 +21,4 @@ try { ?> --EXPECTF-- Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d -Illegal offset type +Cannot access offset of type array on array diff --git a/ext/standard/tests/array/bug68553.phpt b/ext/standard/tests/array/bug68553.phpt index dbb74c7994bb3..7325a68da5413 100644 --- a/ext/standard/tests/array/bug68553.phpt +++ b/ext/standard/tests/array/bug68553.phpt @@ -79,5 +79,5 @@ array(8) { NULL } } -Illegal offset type -Illegal offset type +Cannot access offset of type object on array +Cannot access offset of type array on array From 284c29328ee2116c3025482188d2bd880a7f3f37 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 28 Jan 2023 10:13:58 -0600 Subject: [PATCH 28/92] Fix GH-10437: Set active fiber to null on bailout (#10443) --- NEWS | 2 ++ Zend/tests/fibers/gh10437.phpt | 18 ++++++++++++++++++ Zend/zend_fibers.c | 1 + 3 files changed, 21 insertions(+) create mode 100644 Zend/tests/fibers/gh10437.phpt diff --git a/NEWS b/NEWS index 411201c1acca1..3583a625cf8cb 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ PHP NEWS . Fixed overflow check in OnUpdateMemoryConsumption. (nielsdos) . Fixed bug GH-9916 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes). (Arnaud) + . Fixed bug GH-10437 (Segfault/assertion when using fibers in shutdown + function after bailout). (trowski) - FFI: . Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos) diff --git a/Zend/tests/fibers/gh10437.phpt b/Zend/tests/fibers/gh10437.phpt new file mode 100644 index 0000000000000..5c793c986ee29 --- /dev/null +++ b/Zend/tests/fibers/gh10437.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-10437 (Segfault/assertion when using fibers in shutdown function after bailout) +--FILE-- +start(); + +?> +--EXPECTF-- +Fatal error: Bailout in fiber in %sgh10437.php on line %d +NULL diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c index caa35c61983be..051a9dceaea7a 100644 --- a/Zend/zend_fibers.c +++ b/Zend/zend_fibers.c @@ -543,6 +543,7 @@ static zend_always_inline zend_fiber_transfer zend_fiber_switch_to( /* Forward bailout into current fiber. */ if (UNEXPECTED(transfer.flags & ZEND_FIBER_TRANSFER_FLAG_BAILOUT)) { + EG(active_fiber) = NULL; zend_bailout(); } From 5e1b9666a9a571077986c9be603858961c55c669 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 28 Jan 2023 10:18:12 -0600 Subject: [PATCH 29/92] [ci skip] NEWS --- NEWS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 5594fb3855dd9..6fbe29aae41ec 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ PHP NEWS . Fixed overflow check in OnUpdateMemoryConsumption. (nielsdos) . Fixed bug GH-9916 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes). (Arnaud) + . Fixed bug GH-10437 (Segfault/assertion when using fibers in shutdown + function after bailout). (trowski) - FFI: . Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos) @@ -554,4 +556,3 @@ PHP NEWS . On Windows, the Zip extension is now built as shared library (DLL) by default. (cmb) . Implement fseek for zip stream when possible with libzip 1.9.1. (Remi) - From ec4939b170caca3602c0e1e739c0ab28aa5d5208 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 28 Jan 2023 00:07:35 +0100 Subject: [PATCH 30/92] Fix incorrect check in phar tar parsing The entry.flags was used to check whether the entry has the directory flag. The flags however were masked to only contain the permissions. We need to check the mode, before the permission masking, instead of the flags to check whether it is a directory. Closes GH-10464 Signed-off-by: George Peter Banyard --- NEWS | 3 +++ ext/phar/tar.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 3583a625cf8cb..8d7c133fc4a2e 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ PHP NEWS - Opcache: . Fix incorrect page_size check. (nielsdos) +- Phar: + . Fix incorrect check in phar tar parsing. (nielsdos) + - Standard: . Fixed bug GH-10292 (Made the default value of the first param of srand() and mt_srand() unknown). (kocsismate) diff --git a/ext/phar/tar.c b/ext/phar/tar.c index e56d3e8e3211c..99b6b9812de18 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -478,14 +478,15 @@ int phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alia return FAILURE; } + uint32_t entry_mode = phar_tar_number(hdr->mode, sizeof(hdr->mode)); entry.tar_type = ((old & (hdr->typeflag == '\0')) ? TAR_FILE : hdr->typeflag); entry.offset = entry.offset_abs = pos; /* header_offset unused in tar */ entry.fp_type = PHAR_FP; - entry.flags = phar_tar_number(hdr->mode, sizeof(hdr->mode)) & PHAR_ENT_PERM_MASK; + entry.flags = entry_mode & PHAR_ENT_PERM_MASK; entry.timestamp = phar_tar_number(hdr->mtime, sizeof(hdr->mtime)); entry.is_persistent = myphar->is_persistent; - if (old && entry.tar_type == TAR_FILE && S_ISDIR(entry.flags)) { + if (old && entry.tar_type == TAR_FILE && S_ISDIR(entry_mode)) { entry.tar_type = TAR_DIR; } From 908d954de05e592cb2612bdce6ce8661be9dead1 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 28 Jan 2023 19:44:37 +0000 Subject: [PATCH 31/92] sockets updlite protocol support, with checksum coverage settings. Close GH-10468 --- NEWS | 2 ++ UPGRADING | 3 +++ ext/sockets/sockets.stub.php | 21 +++++++++++++++++++++ ext/sockets/sockets_arginfo.h | 11 ++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index d5e883d9d7745..ec0475c4779ef 100644 --- a/NEWS +++ b/NEWS @@ -98,6 +98,8 @@ PHP NEWS ACK delays. (David Carlier) . Added DONTFRAGMENT support for path MTU discovery purpose. (David Carlier) . Added AF_DIVERT for raw socket for divert ports. (David Carlier) + . Added SOL_UPDLITE, UDPLITE_RECV_CSCOV and UDPLITE_SEND_CSCOV for updlite + protocol support. (David Carlier) - Standard: . E_NOTICEs emitted by unserialize() have been promoted to E_WARNING. (timwolla) diff --git a/UPGRADING b/UPGRADING index 589692aa1e446..9b5febd600377 100644 --- a/UPGRADING +++ b/UPGRADING @@ -141,6 +141,9 @@ PHP 8.3 UPGRADE NOTES . IP_PMTUDISC_INTERFACE (Linux only). . IP_PMTUDISC_OMIT (Linux only). . AF_DIVERT (FreeBSD only). + . SOL_UDPLITE. + . UDPLITE_RECV_CSCOV. + . UDPLITE_SEND_CSCOV. ======================================== 11. Changes to INI File Handling diff --git a/ext/sockets/sockets.stub.php b/ext/sockets/sockets.stub.php index 2db842810a611..82969270fb846 100644 --- a/ext/sockets/sockets.stub.php +++ b/ext/sockets/sockets.stub.php @@ -1525,6 +1525,13 @@ * @cvalue IPPROTO_UDP */ const SOL_UDP = UNKNOWN; +#ifdef IPPROTO_UDPLITE +/** + * @var int + * @cvalue IPPROTO_UDPLITE + */ +const SOL_UDPLITE = UNKNOWN; +#endif #if HAVE_IPV6 /** @@ -1769,6 +1776,20 @@ */ const IP_PMTUDISC_OMIT = UNKNOWN; #endif +#if defined(UDPLITE_SEND_CSCOV) +/** + * @var int + * @cvalue UDPLITE_SEND_CSCOV + */ +const UDPLITE_SEND_CSCOV = UNKNOWN; +#endif +#if defined(UDPLITE_RECV_CSCOV) +/** + * @var int + * @cvalue UDPLITE_RECV_CSCOV + */ +const UDPLITE_RECV_CSCOV = UNKNOWN; +#endif /** * @strict-properties diff --git a/ext/sockets/sockets_arginfo.h b/ext/sockets/sockets_arginfo.h index eca944ba52136..f630d829f4cd6 100644 --- a/ext/sockets/sockets_arginfo.h +++ b/ext/sockets/sockets_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: bf1d22072bd147128a33d82f8b3fc441cf95156a */ + * Stub hash: d02c3c772eab5d9c1310839d2464887993f8e8de */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1) @@ -915,6 +915,9 @@ static void register_sockets_symbols(int module_number) #endif REGISTER_LONG_CONSTANT("SOL_TCP", IPPROTO_TCP, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SOL_UDP", IPPROTO_UDP, CONST_PERSISTENT); +#if defined(IPPROTO_UDPLITE) + REGISTER_LONG_CONSTANT("SOL_UDPLITE", IPPROTO_UDPLITE, CONST_PERSISTENT); +#endif #if HAVE_IPV6 REGISTER_LONG_CONSTANT("IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS, CONST_PERSISTENT); #endif @@ -1018,6 +1021,12 @@ static void register_sockets_symbols(int module_number) #if defined(IP_PMTUDISC_OMIT) REGISTER_LONG_CONSTANT("IP_PMTUDISC_OMIT", IP_PMTUDISC_OMIT, CONST_PERSISTENT); #endif +#if defined(UDPLITE_SEND_CSCOV) + REGISTER_LONG_CONSTANT("UDPLITE_SEND_CSCOV", UDPLITE_SEND_CSCOV, CONST_PERSISTENT); +#endif +#if defined(UDPLITE_RECV_CSCOV) + REGISTER_LONG_CONSTANT("UDPLITE_RECV_CSCOV", UDPLITE_RECV_CSCOV, CONST_PERSISTENT); +#endif } static zend_class_entry *register_class_Socket(void) From 81607a62ca85d016699e16344a5cebca9edba46a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 30 Jan 2023 13:15:05 +0300 Subject: [PATCH 32/92] Fix type inference Fixes oss-fuzz #55358 --- Zend/Optimizer/zend_inference.c | 18 ++++++++++++-- ext/opcache/tests/jit/assign_obj_op_003.phpt | 26 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 ext/opcache/tests/jit/assign_obj_op_003.phpt diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c index dfb70a3dcabf0..33b01dda038f4 100644 --- a/Zend/Optimizer/zend_inference.c +++ b/Zend/Optimizer/zend_inference.c @@ -2537,12 +2537,26 @@ static zend_always_inline int _zend_update_type_info( } else if (opline->opcode == ZEND_ASSIGN_OBJ_OP) { /* The return value must also satisfy the property type */ if (prop_info) { - tmp &= zend_fetch_prop_type(script, prop_info, NULL); + t1 = zend_fetch_prop_type(script, prop_info, NULL); + if ((t1 & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_LONG + && (tmp & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_DOUBLE) { + /* DOUBLE may be auto-converted to LONG */ + tmp |= MAY_BE_LONG; + tmp &= ~MAY_BE_DOUBLE; + } + tmp &= t1; } } else if (opline->opcode == ZEND_ASSIGN_STATIC_PROP_OP) { /* The return value must also satisfy the property type */ if (prop_info) { - tmp &= zend_fetch_prop_type(script, prop_info, NULL); + t1 = zend_fetch_prop_type(script, prop_info, NULL); + if ((t1 & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_LONG + && (tmp & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_DOUBLE) { + /* DOUBLE may be auto-converted to LONG */ + tmp |= MAY_BE_LONG; + tmp &= ~MAY_BE_DOUBLE; + } + tmp &= t1; } } else { if (tmp & MAY_BE_REF) { diff --git a/ext/opcache/tests/jit/assign_obj_op_003.phpt b/ext/opcache/tests/jit/assign_obj_op_003.phpt new file mode 100644 index 0000000000000..325583e84d912 --- /dev/null +++ b/ext/opcache/tests/jit/assign_obj_op_003.phpt @@ -0,0 +1,26 @@ +--TEST-- +JIT ASSIGN_OBJ_OP: invalid type inference +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +--FILE-- +bar += 1.3; + } catch(y) { + } + } +} +var_dump(new Foo); +?> +--EXPECTF-- +Deprecated: Implicit conversion from float 1.3 to int loses precision in %sassign_obj_op_003.php on line 6 +object(Foo)#1 (1) { + ["bar"]=> + int(1) +} From b9bca2dadb0d8d554615f944c3fbff6e0750d72d Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 30 Jan 2023 11:59:12 +0100 Subject: [PATCH 33/92] Fix resetting ZEND_GENERATOR_IN_FIBER flag Signed-off-by: Bob Weinand --- Zend/tests/gh9916-012.phpt | 17 +++++++++++++++++ Zend/zend_generators.c | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/gh9916-012.phpt diff --git a/Zend/tests/gh9916-012.phpt b/Zend/tests/gh9916-012.phpt new file mode 100644 index 0000000000000..cd31ea1215b64 --- /dev/null +++ b/Zend/tests/gh9916-012.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug GH-9916 012 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); +}); +$fiber->start(); + +?> +==DONE== +--EXPECT-- +==DONE== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 24316dc4e896b..65feafc1b6923 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -747,7 +747,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ zend_observer_fcall_end(generator->execute_data, &generator->value); } } - generator->flags &= ~ZEND_GENERATOR_CURRENTLY_RUNNING; + generator->flags &= ~(ZEND_GENERATOR_CURRENTLY_RUNNING | ZEND_GENERATOR_IN_FIBER); generator->frozen_call_stack = NULL; if (EXPECTED(generator->execute_data) && @@ -787,7 +787,6 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ goto try_again; } - generator->flags &= ~ZEND_GENERATOR_IN_FIBER; orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT; } /* }}} */ From 00be6e1aed5e55c04f716a7364ff55e698e154a5 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 30 Jan 2023 12:32:53 +0100 Subject: [PATCH 34/92] Look at executing generator for fiber destructor behaviour --- Zend/tests/fibers/get-return-after-bailout.phpt | 7 +++++++ Zend/tests/generators/gh9801.phpt | 7 +++++++ Zend/zend_generators.c | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Zend/tests/fibers/get-return-after-bailout.phpt b/Zend/tests/fibers/get-return-after-bailout.phpt index 0f004070251b5..04bd464cfab0e 100644 --- a/Zend/tests/fibers/get-return-after-bailout.phpt +++ b/Zend/tests/fibers/get-return-after-bailout.phpt @@ -1,5 +1,12 @@ --TEST-- Fiber::getReturn() after bailout +--SKIPIF-- + --FILE-- --FILE-- flags & ZEND_GENERATOR_IN_FIBER) { + if (zend_generator_get_current(generator)->flags & ZEND_GENERATOR_IN_FIBER) { /* Prevent finally blocks from yielding */ generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; return; From 3eb9dd47e04c4fd3eb220f637c556217bdb088df Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 21 Dec 2021 20:01:55 +0000 Subject: [PATCH 35/92] Use bool and zend_result where it makes sense in sockets extension --- ext/sockets/multicast.c | 18 +++++++++--------- ext/sockets/multicast.h | 6 +++--- ext/sockets/php_sockets.h | 2 +- ext/sockets/sockaddr_conv.c | 2 +- ext/sockets/sockets.c | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index ef32661be09ff..82672e68f2bab 100644 --- a/ext/sockets/multicast.c +++ b/ext/sockets/multicast.c @@ -59,7 +59,7 @@ static const char *_php_source_op_to_string(enum source_op sop); static int _php_source_op_to_ipv4_op(enum source_op sop); #endif -int php_string_to_if_index(const char *val, unsigned *out) +zend_result php_string_to_if_index(const char *val, unsigned *out) { #if HAVE_IF_NAMETOINDEX unsigned int ind; @@ -81,7 +81,7 @@ int php_string_to_if_index(const char *val, unsigned *out) #endif } -static int php_get_if_index_from_zval(zval *val, unsigned *out) +static zend_result php_get_if_index_from_zval(zval *val, unsigned *out) { int ret; @@ -104,7 +104,7 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out) -static int php_get_if_index_from_array(const HashTable *ht, const char *key, +static zend_result php_get_if_index_from_array(const HashTable *ht, const char *key, php_socket *sock, unsigned int *if_index) { zval *val; @@ -117,7 +117,7 @@ static int php_get_if_index_from_array(const HashTable *ht, const char *key, return php_get_if_index_from_zval(val, if_index); } -static int php_get_address_from_array(const HashTable *ht, const char *key, +static zend_result php_get_address_from_array(const HashTable *ht, const char *key, php_socket *sock, php_sockaddr_storage *ss, socklen_t *ss_len) { zval *val; @@ -136,7 +136,7 @@ static int php_get_address_from_array(const HashTable *ht, const char *key, return SUCCESS; } -static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *arg4) +static zend_result php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *arg4) { HashTable *opt_ht; unsigned int if_index; @@ -616,7 +616,7 @@ static int _php_source_op_to_ipv4_op(enum source_op sop) #endif /* HAS_MCAST_EXT */ #ifdef PHP_WIN32 -int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr) +zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr) { MIB_IPADDRTABLE *addr_table; ULONG size; @@ -659,7 +659,7 @@ int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_add return FAILURE; } -int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index) +zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index) { MIB_IPADDRTABLE *addr_table; ULONG size; @@ -709,7 +709,7 @@ int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *i #else -int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr) +zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr) { struct ifreq if_req; @@ -746,7 +746,7 @@ int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_add return SUCCESS; } -int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index) +zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index) { struct ifconf if_conf = {0}; char *buf = NULL, diff --git a/ext/sockets/multicast.h b/ext/sockets/multicast.h index 1e7a0daeb2f20..0362b269728f1 100644 --- a/ext/sockets/multicast.h +++ b/ext/sockets/multicast.h @@ -51,17 +51,17 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock, int optname, zval *arg4); -int php_if_index_to_addr4( +zend_result php_if_index_to_addr4( unsigned if_index, php_socket *php_sock, struct in_addr *out_addr); -int php_add4_to_if_index( +zend_result php_add4_to_if_index( struct in_addr *addr, php_socket *php_sock, unsigned *if_index); -int php_string_to_if_index(const char *val, unsigned *out); +zend_result php_string_to_if_index(const char *val, unsigned *out); int php_mcast_join( php_socket *sock, diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h index fdbc636538cf7..93eba9da0731a 100644 --- a/ext/sockets/php_sockets.h +++ b/ext/sockets/php_sockets.h @@ -126,7 +126,7 @@ enum sockopt_return { }; PHP_SOCKETS_API char *sockets_strerror(int error); -PHP_SOCKETS_API int socket_import_file_descriptor(PHP_SOCKET socket, php_socket *retsock); +PHP_SOCKETS_API bool socket_import_file_descriptor(PHP_SOCKET socket, php_socket *retsock); #else #define phpext_sockets_ptr NULL diff --git a/ext/sockets/sockaddr_conv.c b/ext/sockets/sockaddr_conv.c index 6ec540931f725..e4a7347cafab3 100644 --- a/ext/sockets/sockaddr_conv.c +++ b/ext/sockets/sockaddr_conv.c @@ -9,7 +9,7 @@ #include #endif -extern int php_string_to_if_index(const char *val, unsigned *out); +extern zend_result php_string_to_if_index(const char *val, unsigned *out); #if HAVE_IPV6 /* Sets addr by hostname, or by ip in string form (AF_INET6) */ diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 573b3976701f6..67d4b6630e520 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -223,7 +223,7 @@ ZEND_GET_MODULE(sockets) int inet_ntoa_lock = 0; #endif -static int php_open_listen_sock(php_socket *sock, int port, int backlog) /* {{{ */ +static bool php_open_listen_sock(php_socket *sock, int port, int backlog) /* {{{ */ { struct sockaddr_in la; struct hostent *hp; @@ -266,7 +266,7 @@ static int php_open_listen_sock(php_socket *sock, int port, int backlog) /* {{{ } /* }}} */ -static int php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct sockaddr *la, socklen_t *la_len) /* {{{ */ +static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct sockaddr *la, socklen_t *la_len) /* {{{ */ { out_sock->bsd_socket = accept(in_sock->bsd_socket, la, la_len); @@ -2179,7 +2179,7 @@ PHP_FUNCTION(socket_clear_error) } /* }}} */ -int socket_import_file_descriptor(PHP_SOCKET socket, php_socket *retsock) +bool socket_import_file_descriptor(PHP_SOCKET socket, php_socket *retsock) { #ifdef SO_DOMAIN int type; From 735edd1c177e896d5a44144615626cd2b6a62a5b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 21 Dec 2021 20:03:19 +0000 Subject: [PATCH 36/92] Voidify php_sock_array_from_fd_set() as result is never used --- ext/sockets/sockets.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 67d4b6630e520..b73166f75a8c5 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -526,14 +526,13 @@ static int php_sock_array_to_fd_set(uint32_t arg_num, zval *sock_array, fd_set * } /* }}} */ -static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ +static void php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ { zval *element; zval *dest_element; php_socket *php_sock; zval new_hash; - int num = 0; - zend_ulong num_key; + zend_ulong num_key; zend_string *key; ZEND_ASSERT(Z_TYPE_P(sock_array) == IS_ARRAY); @@ -557,15 +556,12 @@ static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ Z_ADDREF_P(dest_element); } } - num++; } ZEND_HASH_FOREACH_END(); /* Destroy old array, add new one */ zval_ptr_dtor(sock_array); ZVAL_COPY_VALUE(sock_array, &new_hash); - - return num ? 1 : 0; } /* }}} */ From f71e8bfdff009b394fcaf9f8fd4dd94cbc9bc80a Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Mon, 30 Jan 2023 21:23:19 -0300 Subject: [PATCH 37/92] fix: change function name for standardization. --- ext/opcache/jit/zend_jit_helpers.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 63280ad09aab0..268427519edb9 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -32,7 +32,7 @@ static ZEND_COLD void zend_jit_illegal_empty_or_isset_offset(const zval *offset) zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); } -static ZEND_COLD void zend_jit_illegal_offset(zval *offset) +static ZEND_COLD void zend_jit_illegal_array_offset(zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } @@ -493,7 +493,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return; } @@ -635,7 +635,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return; } @@ -873,7 +873,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return NULL; } @@ -1006,7 +1006,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From 85fbc6eaa6cd596f67d533091b50b2e2fcf9b601 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 25 Jan 2023 17:40:28 +0000 Subject: [PATCH 38/92] Fix GH-10152: Custom properties of Date's child classes are not serialised --- ext/date/php_date.c | 165 ++++++++++++++++-- ...TimeImmutable_inherited_serialization.phpt | 23 +++ ...t => DateTimeImmutable_serialization.phpt} | 0 ...eTimeInterval_inherited_serialization.phpt | 22 +++ ...ateTimePeriod_inherited_serialization.phpt | 25 +++ .../DateTimeZone_inherited_serialization.phpt | 22 +++ ...n.phpt => DateTimeZone_serialization.phpt} | 0 .../DateTime_inherited_serialization.phpt | 23 +++ ...ation.phpt => DateTime_serialization.phpt} | 0 ext/date/tests/bug53437_var3.phpt | 2 +- ext/date/tests/bug53437_var5.phpt | 2 +- ext/date/tests/bug53437_var6.phpt | 2 +- ext/date/tests/bug79015.phpt | 2 +- ext/date/tests/gh10152.phpt | 23 +++ 14 files changed, 288 insertions(+), 23 deletions(-) create mode 100644 ext/date/tests/DateTimeImmutable_inherited_serialization.phpt rename ext/date/tests/{DateTimeImmutable_serialisation.phpt => DateTimeImmutable_serialization.phpt} (100%) create mode 100644 ext/date/tests/DateTimeInterval_inherited_serialization.phpt create mode 100644 ext/date/tests/DateTimePeriod_inherited_serialization.phpt create mode 100644 ext/date/tests/DateTimeZone_inherited_serialization.phpt rename ext/date/tests/{DateTimeZone_serialisation.phpt => DateTimeZone_serialization.phpt} (100%) create mode 100644 ext/date/tests/DateTime_inherited_serialization.phpt rename ext/date/tests/{DateTime_serialisation.phpt => DateTime_serialization.phpt} (100%) create mode 100644 ext/date/tests/gh10152.phpt diff --git a/ext/date/php_date.c b/ext/date/php_date.c index fd13e98100848..5a29093e1a0d0 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2254,6 +2254,19 @@ static void date_object_free_storage_period(zend_object *object) /* {{{ */ zend_object_std_dtor(&intern->std); } /* }}} */ +static void add_common_properties(HashTable *myht, zend_object *zobj) +{ + HashTable *common; + zend_string *name; + zval *prop; + + common = zend_std_get_properties(zobj); + + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_IND(common, name, prop) { + zend_hash_add(myht, name, prop); + } ZEND_HASH_FOREACH_END(); +} + /* Advanced Interface */ PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object) /* {{{ */ { @@ -2733,6 +2746,8 @@ PHP_METHOD(DateTime, __serialize) array_init(return_value); myht = Z_ARRVAL_P(return_value); date_object_to_hash(dateobj, myht); + + add_common_properties(myht, &dateobj->std); } /* }}} */ @@ -2751,9 +2766,36 @@ PHP_METHOD(DateTimeImmutable, __serialize) array_init(return_value); myht = Z_ARRVAL_P(return_value); date_object_to_hash(dateobj, myht); + + add_common_properties(myht, &dateobj->std); } /* }}} */ +static bool date_time_is_internal_property(zend_string *name) +{ + if ( + zend_string_equals_literal(name, "date") || + zend_string_equals_literal(name, "timezone_type") || + zend_string_equals_literal(name, "timezone") + ) { + return 1; + } + return 0; +} + +static void restore_custom_datetime_properties(zval *object, HashTable *myht) +{ + zend_string *prop_name; + zval *prop_val; + + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(myht, prop_name, prop_val) { + if (date_time_is_internal_property(prop_name)) { + continue; + } + add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val); + } ZEND_HASH_FOREACH_END(); +} + /* {{{ */ PHP_METHOD(DateTime, __unserialize) { @@ -2772,6 +2814,8 @@ PHP_METHOD(DateTime, __unserialize) if (!php_date_initialize_from_hash(&dateobj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DateTime object"); } + + restore_custom_datetime_properties(object, myht); } /* }}} */ @@ -2793,6 +2837,8 @@ PHP_METHOD(DateTimeImmutable, __unserialize) if (!php_date_initialize_from_hash(&dateobj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DateTimeImmutable object"); } + + restore_custom_datetime_properties(object, myht); } /* }}} */ @@ -3753,9 +3799,35 @@ PHP_METHOD(DateTimeZone, __serialize) array_init(return_value); myht = Z_ARRVAL_P(return_value); date_timezone_object_to_hash(tzobj, myht); + + add_common_properties(myht, &tzobj->std); } /* }}} */ +static bool date_timezone_is_internal_property(zend_string *name) +{ + if ( + zend_string_equals_literal(name, "timezone_type") || + zend_string_equals_literal(name, "timezone") + ) { + return 1; + } + return 0; +} + +static void restore_custom_datetimezone_properties(zval *object, HashTable *myht) +{ + zend_string *prop_name; + zval *prop_val; + + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(myht, prop_name, prop_val) { + if (date_timezone_is_internal_property(prop_name)) { + continue; + } + add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val); + } ZEND_HASH_FOREACH_END(); +} + /* {{{ */ PHP_METHOD(DateTimeZone, __unserialize) { @@ -3774,6 +3846,8 @@ PHP_METHOD(DateTimeZone, __unserialize) if (!php_date_timezone_initialize_from_hash(&object, &tzobj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DateTimeZone object"); } + + restore_custom_datetimezone_properties(object, myht); } /* }}} */ @@ -4344,9 +4418,44 @@ PHP_METHOD(DateInterval, __serialize) array_init(return_value); myht = Z_ARRVAL_P(return_value); date_interval_object_to_hash(intervalobj, myht); + + add_common_properties(myht, &intervalobj->std); } /* }}} */ +static bool date_interval_is_internal_property(zend_string *name) +{ + if ( + zend_string_equals_literal(name, "date_string") || + zend_string_equals_literal(name, "from_string") || + zend_string_equals_literal(name, "y") || + zend_string_equals_literal(name, "m") || + zend_string_equals_literal(name, "d") || + zend_string_equals_literal(name, "h") || + zend_string_equals_literal(name, "i") || + zend_string_equals_literal(name, "s") || + zend_string_equals_literal(name, "f") || + zend_string_equals_literal(name, "invert") || + zend_string_equals_literal(name, "days") + ) { + return 1; + } + return 0; +} + +static void restore_custom_dateinterval_properties(zval *object, HashTable *myht) +{ + zend_string *prop_name; + zval *prop_val; + + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(myht, prop_name, prop_val) { + if (date_interval_is_internal_property(prop_name)) { + continue; + } + add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val); + } ZEND_HASH_FOREACH_END(); +} + /* {{{ */ PHP_METHOD(DateInterval, __unserialize) @@ -4364,6 +4473,7 @@ PHP_METHOD(DateInterval, __unserialize) myht = Z_ARRVAL_P(array); php_date_interval_initialize_from_hash(&object, &intervalobj, myht); + restore_custom_dateinterval_properties(object, myht); } /* }}} */ @@ -5269,9 +5379,44 @@ PHP_METHOD(DatePeriod, __serialize) array_init(return_value); myht = Z_ARRVAL_P(return_value); date_period_object_to_hash(period_obj, myht); + + add_common_properties(myht, &period_obj->std); } /* }}} */ +/* {{{ date_period_is_internal_property + * Common for date_period_read_property(), date_period_write_property(), and + * restore_custom_dateperiod_properties functions + */ +static bool date_period_is_internal_property(zend_string *name) +{ + if ( + zend_string_equals_literal(name, "start") || + zend_string_equals_literal(name, "current") || + zend_string_equals_literal(name, "end") || + zend_string_equals_literal(name, "interval") || + zend_string_equals_literal(name, "recurrences") || + zend_string_equals_literal(name, "include_start_date") || + zend_string_equals_literal(name, "include_end_date") + ) { + return 1; + } + return 0; +} +/* }}} */ + +static void restore_custom_dateperiod_properties(zval *object, HashTable *myht) +{ + zend_string *prop_name; + zval *prop_val; + + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(myht, prop_name, prop_val) { + if (date_period_is_internal_property(prop_name)) { + continue; + } + add_property_zval_ex(object, ZSTR_VAL(prop_name), ZSTR_LEN(prop_name), prop_val); + } ZEND_HASH_FOREACH_END(); +} /* {{{ */ PHP_METHOD(DatePeriod, __unserialize) @@ -5291,6 +5436,7 @@ PHP_METHOD(DatePeriod, __unserialize) if (!php_date_period_initialize_from_hash(period_obj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DatePeriod object"); } + restore_custom_dateperiod_properties(object, myht); } /* }}} */ @@ -5313,25 +5459,6 @@ PHP_METHOD(DatePeriod, __wakeup) } /* }}} */ -/* {{{ date_period_is_internal_property - * Common for date_period_read_property() and date_period_write_property() functions - */ -static bool date_period_is_internal_property(zend_string *name) -{ - if (zend_string_equals_literal(name, "recurrences") - || zend_string_equals_literal(name, "include_start_date") - || zend_string_equals_literal(name, "include_end_date") - || zend_string_equals_literal(name, "start") - || zend_string_equals_literal(name, "current") - || zend_string_equals_literal(name, "end") - || zend_string_equals_literal(name, "interval") - ) { - return 1; - } - return 0; -} -/* }}} */ - /* {{{ date_period_read_property */ static zval *date_period_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv) { diff --git a/ext/date/tests/DateTimeImmutable_inherited_serialization.phpt b/ext/date/tests/DateTimeImmutable_inherited_serialization.phpt new file mode 100644 index 0000000000000..a533b651eed67 --- /dev/null +++ b/ext/date/tests/DateTimeImmutable_inherited_serialization.phpt @@ -0,0 +1,23 @@ +--TEST-- +Inherited DateTimeImmutable serialisation with custom properties +--FILE-- +myProperty); +?> +--EXPECTF-- +bool(true) diff --git a/ext/date/tests/DateTimeImmutable_serialisation.phpt b/ext/date/tests/DateTimeImmutable_serialization.phpt similarity index 100% rename from ext/date/tests/DateTimeImmutable_serialisation.phpt rename to ext/date/tests/DateTimeImmutable_serialization.phpt diff --git a/ext/date/tests/DateTimeInterval_inherited_serialization.phpt b/ext/date/tests/DateTimeInterval_inherited_serialization.phpt new file mode 100644 index 0000000000000..fca8f29b901c9 --- /dev/null +++ b/ext/date/tests/DateTimeInterval_inherited_serialization.phpt @@ -0,0 +1,22 @@ +--TEST-- +Inherited DateTimeInterval serialisation with custom properties +--FILE-- +myProperty); +?> +--EXPECTF-- +bool(true) diff --git a/ext/date/tests/DateTimePeriod_inherited_serialization.phpt b/ext/date/tests/DateTimePeriod_inherited_serialization.phpt new file mode 100644 index 0000000000000..c0d94cf01ef86 --- /dev/null +++ b/ext/date/tests/DateTimePeriod_inherited_serialization.phpt @@ -0,0 +1,25 @@ +--TEST-- +Inherited DateTimePeriod serialisation with custom properties +--FILE-- +myProperty); +?> +--EXPECTF-- +bool(true) diff --git a/ext/date/tests/DateTimeZone_inherited_serialization.phpt b/ext/date/tests/DateTimeZone_inherited_serialization.phpt new file mode 100644 index 0000000000000..d70c983bae7f1 --- /dev/null +++ b/ext/date/tests/DateTimeZone_inherited_serialization.phpt @@ -0,0 +1,22 @@ +--TEST-- +Inherited DateTimeZone serialisation with custom properties +--FILE-- +myProperty); +?> +--EXPECTF-- +bool(true) diff --git a/ext/date/tests/DateTimeZone_serialisation.phpt b/ext/date/tests/DateTimeZone_serialization.phpt similarity index 100% rename from ext/date/tests/DateTimeZone_serialisation.phpt rename to ext/date/tests/DateTimeZone_serialization.phpt diff --git a/ext/date/tests/DateTime_inherited_serialization.phpt b/ext/date/tests/DateTime_inherited_serialization.phpt new file mode 100644 index 0000000000000..5e9101309457b --- /dev/null +++ b/ext/date/tests/DateTime_inherited_serialization.phpt @@ -0,0 +1,23 @@ +--TEST-- +Inherited DateTime serialisation with custom properties +--FILE-- +myProperty); +?> +--EXPECTF-- +bool(true) diff --git a/ext/date/tests/DateTime_serialisation.phpt b/ext/date/tests/DateTime_serialization.phpt similarity index 100% rename from ext/date/tests/DateTime_serialisation.phpt rename to ext/date/tests/DateTime_serialization.phpt diff --git a/ext/date/tests/bug53437_var3.phpt b/ext/date/tests/bug53437_var3.phpt index 6fd5f11f0301b..c87c5c8b9a0cd 100644 --- a/ext/date/tests/bug53437_var3.phpt +++ b/ext/date/tests/bug53437_var3.phpt @@ -4,7 +4,7 @@ Bug #53437 DateInterval unserialize bad data, 32 bit --FILE-- --FILE-- --FILE-- --EXPECTF-- diff --git a/ext/date/tests/gh10152.phpt b/ext/date/tests/gh10152.phpt new file mode 100644 index 0000000000000..7886cf90ef26b --- /dev/null +++ b/ext/date/tests/gh10152.phpt @@ -0,0 +1,23 @@ +--TEST-- +GH-10152: Custom properties of DateTimeImmutable child classes are not serialized +--FILE-- +myProperty); +?> +--EXPECT-- +bool(true) From a42bf93308b159ecda3da01e12b471b13a279d55 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 26 Jan 2023 11:44:07 +0000 Subject: [PATCH 39/92] Fixed GH-10447: 'p' format specifier does not yield 'Z' for 00:00 --- ext/date/php_date.c | 2 +- ext/date/tests/gh10447.phpt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 ext/date/tests/gh10447.phpt diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 0305873eea0e6..fec7d5d03cd63 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -716,7 +716,7 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t /* timezone */ case 'I': length = slprintf(buffer, sizeof(buffer), "%d", localtime ? offset->is_dst : 0); break; case 'p': - if (!localtime || strcmp(offset->abbr, "UTC") == 0 || strcmp(offset->abbr, "Z") == 0) { + if (!localtime || strcmp(offset->abbr, "UTC") == 0 || strcmp(offset->abbr, "Z") == 0 || strcmp(offset->abbr, "GMT+0000") == 0) { length = slprintf(buffer, sizeof(buffer), "%s", "Z"); break; } diff --git a/ext/date/tests/gh10447.phpt b/ext/date/tests/gh10447.phpt new file mode 100644 index 0000000000000..3b7ff54c97fb5 --- /dev/null +++ b/ext/date/tests/gh10447.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug GH-10447 ('p' format specifier does not yield 'Z' for 00:00) +--FILE-- +format('Y-m-d\TH:i:sp'), "\n"; + +$date = new \DateTimeImmutable('2023-01-25T00:00:00-00:00'); +echo $date->format('Y-m-d\TH:i:sp'), "\n"; +?> +--EXPECT-- +2023-01-25T00:00:00Z +2023-01-25T00:00:00Z From 328cce48fa02234dd008ca681148a2d80947aa86 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 31 Jan 2023 15:25:39 -0300 Subject: [PATCH 40/92] fix: change location of functions and apply in ext/spl. --- Zend/zend_API.c | 12 +++++- Zend/zend_execute.c | 15 ------- ext/spl/spl_array.c | 10 ++--- ext/spl/spl_fixedarray.c | 2 +- ext/spl/tests/ArrayObject_illegal_offset.phpt | 10 ++--- ext/spl/tests/fixedarray_001.phpt | 2 +- ext/spl/tests/fixedarray_002.phpt | 2 +- ext/spl/tests/fixedarray_003.phpt | 40 +++++++++---------- 8 files changed, 44 insertions(+), 49 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index ba6f801e24c49..74ead29e21532 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2046,7 +2046,17 @@ ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref) /* } /* }}} */ -ZEND_API void zend_illegal_array_offset(const zval *offset) +void zend_illegal_empty_or_isset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); +} + +void zend_illegal_unset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s on unset", zend_get_type_by_const(Z_TYPE_P(offset))); +} + +void zend_illegal_array_offset(const zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 21314face6c2d..ee4dd16141554 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,21 +1455,6 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_empty_or_isset_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); -} - -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_unset_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on unset", zend_get_type_by_const(Z_TYPE_P(offset))); -} - -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); -} - static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) { zend_type_error("Cannot access offset of type %s on string", zend_zval_type_name(offset)); diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 4098382c61c17..9b6218f7404f5 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -286,7 +286,7 @@ static zend_result get_hash_key(spl_hash_key *key, spl_array_object *intern, zva ZVAL_DEREF(offset); goto try_again; default: - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); return FAILURE; } @@ -313,7 +313,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object * } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval) : &EG(uninitialized_zval); } @@ -466,7 +466,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); zval_ptr_dtor(value); return; } @@ -502,7 +502,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); return; } @@ -566,7 +566,7 @@ static bool spl_array_has_dimension_ex(bool check_inherited, zend_object *object spl_hash_key key; if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type in isset or empty"); + zend_illegal_empty_or_isset_offset(offset); return 0; } diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 465c649e980aa..b05a5cc3dbcff 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -333,7 +333,7 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ return Z_RES_HANDLE_P(offset); } - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); return 0; } diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt index df25e4fa5e0fa..c21c93781a471 100644 --- a/ext/spl/tests/ArrayObject_illegal_offset.phpt +++ b/ext/spl/tests/ArrayObject_illegal_offset.phpt @@ -32,8 +32,8 @@ try { ?> --EXPECT-- -Illegal offset type -Illegal offset type -Illegal offset type -Illegal offset type in isset or empty -Illegal offset type in unset +Cannot access offset of type array on array +Cannot access offset of type array on array +Cannot access offset of type array on array +Cannot access offset of type array in isset or empty +Cannot access offset of type array on unset diff --git a/ext/spl/tests/fixedarray_001.phpt b/ext/spl/tests/fixedarray_001.phpt index a6ab149c75ca5..c1ebf23b1b07f 100644 --- a/ext/spl/tests/fixedarray_001.phpt +++ b/ext/spl/tests/fixedarray_001.phpt @@ -46,7 +46,7 @@ var_dump($b[0]); ?> --EXPECT-- RuntimeException: Index invalid or out of range -TypeError: Illegal offset type +TypeError: Cannot access offset of type string on array RuntimeException: Index invalid or out of range string(6) "value0" string(6) "value2" diff --git a/ext/spl/tests/fixedarray_002.phpt b/ext/spl/tests/fixedarray_002.phpt index 4f6682e6df3a0..93d10770583ec 100644 --- a/ext/spl/tests/fixedarray_002.phpt +++ b/ext/spl/tests/fixedarray_002.phpt @@ -71,7 +71,7 @@ var_dump(count($a), $a->getSize(), count($a) == $a->getSize()); A::offsetSet RuntimeException: Index invalid or out of range A::offsetGet -TypeError: Illegal offset type +TypeError: Cannot access offset of type string on array A::offsetUnset RuntimeException: Index invalid or out of range A::offsetSet diff --git a/ext/spl/tests/fixedarray_003.phpt b/ext/spl/tests/fixedarray_003.phpt index 277088d04f045..bbd5211dca029 100644 --- a/ext/spl/tests/fixedarray_003.phpt +++ b/ext/spl/tests/fixedarray_003.phpt @@ -168,55 +168,55 @@ try { Write context Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array Read context string(1) "a" string(1) "b" Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d string(1) "c" -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d string(1) "f" string(1) "g" -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array isset() bool(true) bool(true) Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d bool(true) -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(true) bool(true) -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array empty() bool(false) bool(false) Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d bool(false) -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(false) bool(false) -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array From f0ff97b382f9922a2aacde04cc1a4efcb6bbe8ba Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 41/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 7efd90a52a5bfb94d079027b844a41005bdf736b Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 42/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 92edc84dcf7352bcc6a8e24a3abd9027104e1001 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Wed, 25 Jan 2023 20:31:01 -0300 Subject: [PATCH 43/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/assign_dim_obj_null_return.phpt | 8 ++++---- Zend/tests/bug79790.phpt | 2 +- Zend/tests/bug79947.phpt | 2 +- Zend/tests/offset_array.phpt | 13 +++++++++++-- Zend/zend_execute.c | 12 ++++++++++++ 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 8f74bccc075f0..3d6e4746ed621 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type object diff --git a/Zend/tests/assign_dim_obj_null_return.phpt b/Zend/tests/assign_dim_obj_null_return.phpt index 0a2ea94c552d5..b2e56ed04528a 100644 --- a/Zend/tests/assign_dim_obj_null_return.phpt +++ b/Zend/tests/assign_dim_obj_null_return.phpt @@ -72,12 +72,12 @@ test(); ?> --EXPECT-- Cannot add element to the array as the next element is already occupied -Illegal offset type -Illegal offset type +Illegal offset type: cannot be of type array +Illegal offset type: cannot be of type object Cannot use a scalar value as an array Cannot add element to the array as the next element is already occupied -Illegal offset type -Illegal offset type +Illegal offset type: cannot be of type array +Illegal offset type: cannot be of type object Cannot use a scalar value as an array Attempt to assign property "foo" on true Attempt to assign property "foo" on true diff --git a/Zend/tests/bug79790.phpt b/Zend/tests/bug79790.phpt index 4fce25291bcb5..125f74aedc339 100644 --- a/Zend/tests/bug79790.phpt +++ b/Zend/tests/bug79790.phpt @@ -8,7 +8,7 @@ function b($a = array()[array ()]) { } ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %s:%d +Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %s:%d Stack trace: #0 %s(%d): b() #1 {main} diff --git a/Zend/tests/bug79947.phpt b/Zend/tests/bug79947.phpt index 906f58144b41d..edfbdaa0b754c 100644 --- a/Zend/tests/bug79947.phpt +++ b/Zend/tests/bug79947.phpt @@ -12,6 +12,6 @@ try { var_dump($array); ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type array array(0) { } diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 0109950cde848..47d7cc9f32e7e 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -30,6 +30,14 @@ try { echo $e->getMessage(), "\n"; } +try{ + $k = []; + $arr = ['foo']; + $arr[$k]; +}catch (Error $e){ + echo $e->getMessage(), "\n"; +} + echo "Done\n"; ?> --EXPECTF-- @@ -48,6 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type -Illegal offset type +Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type array +Illegal offset type: cannot be of type array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index b051937a5bc08..3314ae35b5fcc 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2328,6 +2328,12 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval case IS_TRUE: value->lval = 1; return IS_LONG; + case IS_ARRAY: + zend_type_error("Illegal offset type: cannot be of type array"); + return IS_ARRAY; + case IS_OBJECT: + zend_type_error("Illegal offset type: cannot be of type object"); + return IS_OBJECT; default: zend_illegal_offset(); return IS_NULL; @@ -2402,6 +2408,12 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv case IS_TRUE: value->lval = 1; return IS_LONG; + case IS_ARRAY: + zend_type_error("Illegal offset type: cannot be of type array"); + return IS_ARRAY; + case IS_OBJECT: + zend_type_error("Illegal offset type: cannot be of type object"); + return IS_OBJECT; default: zend_illegal_offset(); return IS_NULL; From 7eba8156272d6c9aa5bbe43c8dfdb1b692d53e9d Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Wed, 25 Jan 2023 20:40:13 -0300 Subject: [PATCH 44/92] inform the type in the array displacement error message. --- ext/opcache/tests/jit/assign_dim_002.phpt | 6 +++--- ext/opcache/tests/jit/assign_dim_op_001.phpt | 4 ++-- ext/opcache/tests/jit/fetch_dim_rw_004.phpt | 2 +- tests/classes/tostring_001.phpt | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 3f713a6c6a6a9..4a03cc2641aca 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type +Illegal offset type: cannot be of type object array(1) { [0]=> array(2) { @@ -198,7 +198,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d int(1) @@ -221,7 +221,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Warning: Undefined variable $undef in %s on line %d NULL diff --git a/ext/opcache/tests/jit/assign_dim_op_001.phpt b/ext/opcache/tests/jit/assign_dim_op_001.phpt index a533cbe9c283b..f63a5de66938b 100644 --- a/ext/opcache/tests/jit/assign_dim_op_001.phpt +++ b/ext/opcache/tests/jit/assign_dim_op_001.phpt @@ -79,7 +79,7 @@ Warning: Undefined array key 2 in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d @@ -104,5 +104,5 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type +Illegal offset type: cannot be of type array Unsupported operand types: null % string diff --git a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt index ea3fff88f1e45..65ad0e0d5a06a 100644 --- a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt +++ b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt @@ -18,7 +18,7 @@ Stack trace: #0 %sfetch_dim_rw_004.php(5): {closure}(2, 'Undefined varia...', '%s', 5) #1 {main} -Next TypeError: Illegal offset type in %sfetch_dim_rw_004.php:5 +Next TypeError: Illegal offset type: cannot be of type array in %sfetch_dim_rw_004.php:5 Stack trace: #0 {main} thrown in %sfetch_dim_rw_004.php on line 5 diff --git a/tests/classes/tostring_001.phpt b/tests/classes/tostring_001.phpt index abf41f97cdaca..df54e08a002cf 100644 --- a/tests/classes/tostring_001.phpt +++ b/tests/classes/tostring_001.phpt @@ -118,7 +118,7 @@ test2::__toString() Converted ====test7==== test2::__toString() -Illegal offset type +Illegal offset type: cannot be of type object ====test8==== test2::__toString() string(9) "Converted" From a63e9debabbd50bb463417924ebae3ec2dbcaf90 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 08:06:29 -0300 Subject: [PATCH 45/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/offset_array.phpt | 2 +- Zend/zend_execute.c | 22 +++---------- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 32 +++++++++---------- ext/opcache/tests/jit/assign_dim_002.phpt | 2 +- ext/opcache/tests/opt/inference_002.phpt | 4 +-- .../tests/array/array_key_exists.phpt | 2 +- 9 files changed, 29 insertions(+), 41 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 3d6e4746ed621..c0f1e6e52ba34 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type Closure diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index e55757bbcd417..c7fa7c1d1d481 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type Closure diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 47d7cc9f32e7e..60d2c1892a6b7 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -56,7 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type stdClass Illegal offset type: cannot be of type array Illegal offset type: cannot be of type array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 3314ae35b5fcc..702a762da8a74 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,9 +1455,9 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(void) +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(const zval *offset) { - zend_type_error("Illegal offset type"); + zend_type_error("Illegal offset type: cannot be of type %s", zend_zval_type_name(offset)); } static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) @@ -2328,14 +2328,8 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval case IS_TRUE: value->lval = 1; return IS_LONG; - case IS_ARRAY: - zend_type_error("Illegal offset type: cannot be of type array"); - return IS_ARRAY; - case IS_OBJECT: - zend_type_error("Illegal offset type: cannot be of type object"); - return IS_OBJECT; default: - zend_illegal_offset(); + zend_illegal_offset(dim); return IS_NULL; } } @@ -2408,14 +2402,8 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv case IS_TRUE: value->lval = 1; return IS_LONG; - case IS_ARRAY: - zend_type_error("Illegal offset type: cannot be of type array"); - return IS_ARRAY; - case IS_OBJECT: - zend_type_error("Illegal offset type: cannot be of type object"); - return IS_OBJECT; default: - zend_illegal_offset(); + zend_illegal_offset(dim); return IS_NULL; } } @@ -2997,7 +2985,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_offset(); + zend_illegal_offset(key); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index fc7cd81323987..09dfe0426e4de 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6055,7 +6055,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index a1eefaa72e336..1cf9ff76a8d9c 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7342,7 +7342,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -9655,7 +9655,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_T str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10578,7 +10578,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_U str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -12020,7 +12020,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -19992,7 +19992,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20432,7 +20432,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20893,7 +20893,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -21293,7 +21293,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25060,7 +25060,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -27468,7 +27468,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -29489,7 +29489,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -31744,7 +31744,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -43236,7 +43236,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CONS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -46836,7 +46836,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_TMPV str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -48741,7 +48741,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_UNUS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52229,7 +52229,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CV_H str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(); + zend_illegal_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 4a03cc2641aca..b5343cf156b35 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type: cannot be of type object +Illegal offset type: cannot be of type Closure array(1) { [0]=> array(2) { diff --git a/ext/opcache/tests/opt/inference_002.phpt b/ext/opcache/tests/opt/inference_002.phpt index 70412426c2fcc..93b0f205cac8e 100644 --- a/ext/opcache/tests/opt/inference_002.phpt +++ b/ext/opcache/tests/opt/inference_002.phpt @@ -9,7 +9,7 @@ opcache.optimization_level=-1 var_dump([[]=>&$x]); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %sinference_002.php:2 +Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %sinference_002.php:2 Stack trace: #0 {main} - thrown in %sinference_002.php on line 2 \ No newline at end of file + thrown in %sinference_002.php on line 2 diff --git a/ext/standard/tests/array/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt index d6f9ca13de718..9513895fbb1a5 100644 --- a/ext/standard/tests/array/array_key_exists.phpt +++ b/ext/standard/tests/array/array_key_exists.phpt @@ -202,7 +202,7 @@ bool(false) bool(true) *** Testing error conditions *** -Illegal offset type +Illegal offset type: cannot be of type array *** Testing operation on objects *** array_key_exists(): Argument #2 ($array) must be of type array, key_check given From be17096602ea836c817ccabf6edf8a17618194b6 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 11:22:08 -0300 Subject: [PATCH 46/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/init_array_illegal_offset_type.phpt | 2 +- Zend/tests/offset_array.phpt | 2 +- Zend/zend_execute.c | 2 +- ext/opcache/tests/jit/assign_dim_002.phpt | 2 +- ext/standard/tests/array/array_key_exists_variation1.phpt | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index c0f1e6e52ba34..3d6e4746ed621 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type Closure +Illegal offset type: cannot be of type object diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index c7fa7c1d1d481..697a634f3caa8 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type Closure +Illegal offset type: cannot be of type object diff --git a/Zend/tests/init_array_illegal_offset_type.phpt b/Zend/tests/init_array_illegal_offset_type.phpt index 2243ca2905ea0..e7f2f917bd0de 100644 --- a/Zend/tests/init_array_illegal_offset_type.phpt +++ b/Zend/tests/init_array_illegal_offset_type.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -Illegal offset type +Illegal offset type: cannot be of type object diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 60d2c1892a6b7..47d7cc9f32e7e 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -56,7 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type: cannot be of type stdClass +Illegal offset type: cannot be of type object Illegal offset type: cannot be of type array Illegal offset type: cannot be of type array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 702a762da8a74..0bc344760382a 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1457,7 +1457,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(const zval *offset) { - zend_type_error("Illegal offset type: cannot be of type %s", zend_zval_type_name(offset)); + zend_type_error("Illegal offset type: cannot be of type %s", zend_get_type_by_const(Z_TYPE_P(offset))); } static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index b5343cf156b35..4a03cc2641aca 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type: cannot be of type Closure +Illegal offset type: cannot be of type object array(1) { [0]=> array(2) { diff --git a/ext/standard/tests/array/array_key_exists_variation1.phpt b/ext/standard/tests/array/array_key_exists_variation1.phpt index 3a410258bb999..c34896e2c78f0 100644 --- a/ext/standard/tests/array/array_key_exists_variation1.phpt +++ b/ext/standard/tests/array/array_key_exists_variation1.phpt @@ -129,7 +129,7 @@ bool(false) bool(false) -- Iteration 13 -- -Illegal offset type +Illegal offset type: cannot be of type array -- Iteration 14 -- bool(true) @@ -141,7 +141,7 @@ bool(true) bool(true) -- Iteration 17 -- -Illegal offset type +Illegal offset type: cannot be of type object -- Iteration 18 -- bool(false) From a19d295b91e24393ee4b5b612aacdacf6b80a779 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 47/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 6d24bb743ae27646538ae184a048e8b9e60c38ee Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 48/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From e51f09d0592cb0168b703b87aeb05f51782ebacf Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 49/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 998a5dde6c58dca8f085ddd7e6318275b9edbda0 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 50/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 2d73ebb4ac58c0c72cf3d01f2bbe64661b6e003b Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 51/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 627104017c8d9e6843946e8f85ccf376c6016b0e Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 52/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 74bf5d84ebb4c4dfa6f785fc3ee3eb4da6fe3dff Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 53/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 6dbaa72c56c79308ad268a8e620ea43cd73c518f Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 54/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From f8cd06f2dd52b530a525a8353676b7f267fa81e9 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 16:54:14 -0300 Subject: [PATCH 55/92] inform the type in the array displacement error message. --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/assign_dim_obj_null_return.phpt | 8 ++--- Zend/tests/bug79790.phpt | 2 +- Zend/tests/bug79947.phpt | 2 +- .../tests/init_array_illegal_offset_type.phpt | 2 +- Zend/tests/offset_array.phpt | 6 ++-- Zend/zend_execute.c | 10 +++--- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 32 +++++++++---------- ext/opcache/tests/jit/assign_dim_002.phpt | 6 ++-- ext/opcache/tests/jit/assign_dim_op_001.phpt | 4 +-- ext/opcache/tests/jit/fetch_dim_rw_004.phpt | 2 +- ext/opcache/tests/opt/inference_002.phpt | 2 +- .../tests/array/array_key_exists.phpt | 2 +- .../array/array_key_exists_variation1.phpt | 4 +-- tests/classes/tostring_001.phpt | 2 +- 17 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 3d6e4746ed621..4037d3d0e3d21 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index 697a634f3caa8..4f822a6f5a154 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array diff --git a/Zend/tests/assign_dim_obj_null_return.phpt b/Zend/tests/assign_dim_obj_null_return.phpt index b2e56ed04528a..02e709818669e 100644 --- a/Zend/tests/assign_dim_obj_null_return.phpt +++ b/Zend/tests/assign_dim_obj_null_return.phpt @@ -72,12 +72,12 @@ test(); ?> --EXPECT-- Cannot add element to the array as the next element is already occupied -Illegal offset type: cannot be of type array -Illegal offset type: cannot be of type object +Cannot access offset of type array on array +Cannot access offset of type object on array Cannot use a scalar value as an array Cannot add element to the array as the next element is already occupied -Illegal offset type: cannot be of type array -Illegal offset type: cannot be of type object +Cannot access offset of type array on array +Cannot access offset of type object on array Cannot use a scalar value as an array Attempt to assign property "foo" on true Attempt to assign property "foo" on true diff --git a/Zend/tests/bug79790.phpt b/Zend/tests/bug79790.phpt index 125f74aedc339..0d34e2be0fc1e 100644 --- a/Zend/tests/bug79790.phpt +++ b/Zend/tests/bug79790.phpt @@ -8,7 +8,7 @@ function b($a = array()[array ()]) { } ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %s:%d Stack trace: #0 %s(%d): b() #1 {main} diff --git a/Zend/tests/bug79947.phpt b/Zend/tests/bug79947.phpt index edfbdaa0b754c..0593eacfd6c48 100644 --- a/Zend/tests/bug79947.phpt +++ b/Zend/tests/bug79947.phpt @@ -12,6 +12,6 @@ try { var_dump($array); ?> --EXPECT-- -Illegal offset type: cannot be of type array +Cannot access offset of type array on array array(0) { } diff --git a/Zend/tests/init_array_illegal_offset_type.phpt b/Zend/tests/init_array_illegal_offset_type.phpt index e7f2f917bd0de..2e5a0401d6e4a 100644 --- a/Zend/tests/init_array_illegal_offset_type.phpt +++ b/Zend/tests/init_array_illegal_offset_type.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 47d7cc9f32e7e..c526beca91a89 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -56,7 +56,7 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Illegal offset type: cannot be of type object -Illegal offset type: cannot be of type array -Illegal offset type: cannot be of type array +Cannot access offset of type object on array +Cannot access offset of type array on array +Cannot access offset of type array on array Done diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 0bc344760382a..bb79f6de8aeca 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,9 +1455,9 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(const zval *offset) +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset) { - zend_type_error("Illegal offset type: cannot be of type %s", zend_get_type_by_const(Z_TYPE_P(offset))); + zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) @@ -2329,7 +2329,7 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval value->lval = 1; return IS_LONG; default: - zend_illegal_offset(dim); + zend_illegal_array_offset(dim); return IS_NULL; } } @@ -2403,7 +2403,7 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv value->lval = 1; return IS_LONG; default: - zend_illegal_offset(dim); + zend_illegal_array_offset(dim); return IS_NULL; } } @@ -2985,7 +2985,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_offset(key); + zend_illegal_array_offset(key); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 09dfe0426e4de..6c07924e99cd1 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6055,7 +6055,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 1cf9ff76a8d9c..8eb981c07063d 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7342,7 +7342,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -9655,7 +9655,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_T str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10578,7 +10578,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_U str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -12020,7 +12020,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CONST_C str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -19992,7 +19992,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20432,7 +20432,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20893,7 +20893,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -21293,7 +21293,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_TMP_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25060,7 +25060,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CON str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -27468,7 +27468,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_TMP str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -29489,7 +29489,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_UNU str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -31744,7 +31744,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_VAR_CV_ str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -43236,7 +43236,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CONS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -46836,7 +46836,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_TMPV str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -48741,7 +48741,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_UNUS str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52229,7 +52229,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_ELEMENT_SPEC_CV_CV_H str = ZSTR_EMPTY_ALLOC(); goto str_index; } else { - zend_illegal_offset(offset); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 4a03cc2641aca..83b4bfdec7873 100644 --- a/ext/opcache/tests/jit/assign_dim_002.phpt +++ b/ext/opcache/tests/jit/assign_dim_002.phpt @@ -161,7 +161,7 @@ array(1) { int(1) } } -Illegal offset type: cannot be of type object +Cannot access offset of type object on array array(1) { [0]=> array(2) { @@ -198,7 +198,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d int(1) @@ -221,7 +221,7 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Warning: Undefined variable $undef in %s on line %d NULL diff --git a/ext/opcache/tests/jit/assign_dim_op_001.phpt b/ext/opcache/tests/jit/assign_dim_op_001.phpt index f63a5de66938b..731a2e96420a7 100644 --- a/ext/opcache/tests/jit/assign_dim_op_001.phpt +++ b/ext/opcache/tests/jit/assign_dim_op_001.phpt @@ -79,7 +79,7 @@ Warning: Undefined array key 2 in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Deprecated: Automatic conversion of false to array is deprecated in %s on line %d @@ -104,5 +104,5 @@ array(1) { } Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Illegal offset type: cannot be of type array +Cannot access offset of type array on array Unsupported operand types: null % string diff --git a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt index 65ad0e0d5a06a..d9302b8fd04ce 100644 --- a/ext/opcache/tests/jit/fetch_dim_rw_004.phpt +++ b/ext/opcache/tests/jit/fetch_dim_rw_004.phpt @@ -18,7 +18,7 @@ Stack trace: #0 %sfetch_dim_rw_004.php(5): {closure}(2, 'Undefined varia...', '%s', 5) #1 {main} -Next TypeError: Illegal offset type: cannot be of type array in %sfetch_dim_rw_004.php:5 +Next TypeError: Cannot access offset of type array on array in %sfetch_dim_rw_004.php:5 Stack trace: #0 {main} thrown in %sfetch_dim_rw_004.php on line 5 diff --git a/ext/opcache/tests/opt/inference_002.phpt b/ext/opcache/tests/opt/inference_002.phpt index 93b0f205cac8e..3d8c69d054e5d 100644 --- a/ext/opcache/tests/opt/inference_002.phpt +++ b/ext/opcache/tests/opt/inference_002.phpt @@ -9,7 +9,7 @@ opcache.optimization_level=-1 var_dump([[]=>&$x]); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type: cannot be of type array in %sinference_002.php:2 +Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %sinference_002.php:2 Stack trace: #0 {main} thrown in %sinference_002.php on line 2 diff --git a/ext/standard/tests/array/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt index 9513895fbb1a5..8cc2f9c5207c2 100644 --- a/ext/standard/tests/array/array_key_exists.phpt +++ b/ext/standard/tests/array/array_key_exists.phpt @@ -202,7 +202,7 @@ bool(false) bool(true) *** Testing error conditions *** -Illegal offset type: cannot be of type array +Cannot access offset of type array on array *** Testing operation on objects *** array_key_exists(): Argument #2 ($array) must be of type array, key_check given diff --git a/ext/standard/tests/array/array_key_exists_variation1.phpt b/ext/standard/tests/array/array_key_exists_variation1.phpt index c34896e2c78f0..eb35d1bfae0c1 100644 --- a/ext/standard/tests/array/array_key_exists_variation1.phpt +++ b/ext/standard/tests/array/array_key_exists_variation1.phpt @@ -129,7 +129,7 @@ bool(false) bool(false) -- Iteration 13 -- -Illegal offset type: cannot be of type array +Cannot access offset of type array on array -- Iteration 14 -- bool(true) @@ -141,7 +141,7 @@ bool(true) bool(true) -- Iteration 17 -- -Illegal offset type: cannot be of type object +Cannot access offset of type object on array -- Iteration 18 -- bool(false) diff --git a/tests/classes/tostring_001.phpt b/tests/classes/tostring_001.phpt index df54e08a002cf..ddbe4d152dde0 100644 --- a/tests/classes/tostring_001.phpt +++ b/tests/classes/tostring_001.phpt @@ -118,7 +118,7 @@ test2::__toString() Converted ====test7==== test2::__toString() -Illegal offset type: cannot be of type object +Cannot access offset of type object on array ====test8==== test2::__toString() string(9) "Converted" From e04ccc9595bb4f24d0e9ee914830d36a348c52ec Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:09:27 -0300 Subject: [PATCH 56/92] Revert "Fix overflow check in OnUpdateMemoryConsumption (#10456)" This reverts commit 63cac9520a6126e141838371f5fbcae9683d067c. --- ext/opcache/zend_accelerator_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 45a39da7da535..2eb0b38a7a38b 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -72,8 +72,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption) zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption is set below the required 8MB.\n"); return FAILURE; } - if (UNEXPECTED(memsize > ZEND_LONG_MAX / (1024 * 1024))) { - *p = ZEND_LONG_MAX; + if (UNEXPECTED(memsize > ZEND_ULONG_MAX / (1024 * 1024))) { + *p = ZEND_ULONG_MAX; } else { *p = memsize * (1024 * 1024); } From 83d8284f6f45bc7b781db1d811f9fe69e4995e17 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:09:36 -0300 Subject: [PATCH 57/92] Revert "Prevent dtor of generator in suspended fiber (#10462)" This reverts commit aeca4d222bd241e9cfd5e24a0d35a256b904e11f. --- Zend/tests/gh9916-001.phpt | 27 ------------------ Zend/tests/gh9916-002.phpt | 21 -------------- Zend/tests/gh9916-003.phpt | 36 ------------------------ Zend/tests/gh9916-004.phpt | 26 ----------------- Zend/tests/gh9916-005.phpt | 25 ----------------- Zend/tests/gh9916-006.phpt | 37 ------------------------- Zend/tests/gh9916-007.phpt | 57 -------------------------------------- Zend/tests/gh9916-008.phpt | 47 ------------------------------- Zend/tests/gh9916-009.phpt | 35 ----------------------- Zend/tests/gh9916-010.phpt | 34 ----------------------- Zend/tests/gh9916-011.phpt | 41 --------------------------- Zend/zend_generators.c | 3 +- Zend/zend_generators.h | 1 - 13 files changed, 2 insertions(+), 388 deletions(-) delete mode 100644 Zend/tests/gh9916-001.phpt delete mode 100644 Zend/tests/gh9916-002.phpt delete mode 100644 Zend/tests/gh9916-003.phpt delete mode 100644 Zend/tests/gh9916-004.phpt delete mode 100644 Zend/tests/gh9916-005.phpt delete mode 100644 Zend/tests/gh9916-006.phpt delete mode 100644 Zend/tests/gh9916-007.phpt delete mode 100644 Zend/tests/gh9916-008.phpt delete mode 100644 Zend/tests/gh9916-009.phpt delete mode 100644 Zend/tests/gh9916-010.phpt delete mode 100644 Zend/tests/gh9916-011.phpt diff --git a/Zend/tests/gh9916-001.phpt b/Zend/tests/gh9916-001.phpt deleted file mode 100644 index 3e518807238bc..0000000000000 --- a/Zend/tests/gh9916-001.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally diff --git a/Zend/tests/gh9916-002.phpt b/Zend/tests/gh9916-002.phpt deleted file mode 100644 index 6f0b81cf3e91a..0000000000000 --- a/Zend/tests/gh9916-002.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-003.phpt b/Zend/tests/gh9916-003.phpt deleted file mode 100644 index c4bfb815118bc..0000000000000 --- a/Zend/tests/gh9916-003.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally (inner) -Finally diff --git a/Zend/tests/gh9916-004.phpt b/Zend/tests/gh9916-004.phpt deleted file mode 100644 index 1a51a841e8bb6..0000000000000 --- a/Zend/tests/gh9916-004.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-005.phpt b/Zend/tests/gh9916-005.phpt deleted file mode 100644 index f84c756919cd0..0000000000000 --- a/Zend/tests/gh9916-005.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -send($fiber); - $gen->current(); -}); -$fiber->start(); - -$gen = null; -$fiber = null; -gc_collect_cycles(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-006.phpt b/Zend/tests/gh9916-006.phpt deleted file mode 100644 index 28c57105c7b1f..0000000000000 --- a/Zend/tests/gh9916-006.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Fiber return\n"; -}); -$fiber->start(); -$fiber->resume(); -$gen->next(); -$gen->current(); -?> -==DONE== ---EXPECT-- -Before suspend -After suspend -Fiber return -Before exit diff --git a/Zend/tests/gh9916-007.phpt b/Zend/tests/gh9916-007.phpt deleted file mode 100644 index e1ec3fb19f32b..0000000000000 --- a/Zend/tests/gh9916-007.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally (iterator) -Finally diff --git a/Zend/tests/gh9916-008.phpt b/Zend/tests/gh9916-008.phpt deleted file mode 100644 index 84521d69e2120..0000000000000 --- a/Zend/tests/gh9916-008.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-009.phpt b/Zend/tests/gh9916-009.phpt deleted file mode 100644 index 75643d871dea0..0000000000000 --- a/Zend/tests/gh9916-009.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- - new stdClass]; - print "Not executed\n"; - } -})(); -$fiber = new Fiber(function() use ($gen, &$fiber) { - $gen->current(); - print "Not executed\n"; -}); -$fiber->start(); -?> -==DONE== ---EXPECTF-- -Before suspend -==DONE== -Finally - -Fatal error: Uncaught Error: Cannot use "yield from" in a force-closed generator in %s:%d -Stack trace: -#0 [internal function]: {closure}() -#1 %s(%d): Generator->current() -#2 [internal function]: {closure}() -#3 {main} - thrown in %s on line %d diff --git a/Zend/tests/gh9916-010.phpt b/Zend/tests/gh9916-010.phpt deleted file mode 100644 index d3a841d7ceb31..0000000000000 --- a/Zend/tests/gh9916-010.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Before next\n"; - $gen->next(); - print "Not executed\n"; -}); - -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before current -Before yield -Before yield 2 -Before next -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-011.phpt b/Zend/tests/gh9916-011.phpt deleted file mode 100644 index 05fa884c29337..0000000000000 --- a/Zend/tests/gh9916-011.phpt +++ /dev/null @@ -1,41 +0,0 @@ ---TEST-- -Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -next(); - } -})(); - -$fiber = new Fiber(function () use ($gen, &$fiber) { - print "Before current\n"; - $gen->current(); - print "Before next\n"; - $gen->next(); - print "Not executed\n"; -}); - -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before current -Before yield -Before yield 2 -Before next -Before suspend -==DONE== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 7dc15bcbe30dd..ed2bd039708e9 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -761,7 +761,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ zend_observer_fcall_end(generator->execute_data, &generator->value); } } - generator->flags &= ~(ZEND_GENERATOR_CURRENTLY_RUNNING | ZEND_GENERATOR_IN_FIBER); + generator->flags &= ~ZEND_GENERATOR_CURRENTLY_RUNNING; generator->frozen_call_stack = NULL; if (EXPECTED(generator->execute_data) && @@ -801,6 +801,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ goto try_again; } + generator->flags &= ~ZEND_GENERATOR_IN_FIBER; orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT; } /* }}} */ diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h index 4ccc42b92f668..17b25a99b87c1 100644 --- a/Zend/zend_generators.h +++ b/Zend/zend_generators.h @@ -92,7 +92,6 @@ static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1; static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2; static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4; static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8; -static const zend_uchar ZEND_GENERATOR_IN_FIBER = 0x10; void zend_register_generator_ce(void); ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution); From 32387687a80fcf8a324ed3a674ceac5a7a166961 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:44:48 -0300 Subject: [PATCH 58/92] fix: handle JIT helper. --- ext/opcache/jit/zend_jit_helpers.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index c594ade575bed..d2285cafac370 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,9 +27,9 @@ static ZEND_COLD void undef_result_after_exception(void) { } } -static ZEND_COLD void zend_jit_illegal_offset(void) +static ZEND_COLD void zend_jit_illegal_offset(zval *offset) { - zend_type_error("Illegal offset type"); + zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } static ZEND_COLD void zend_jit_illegal_string_offset(zval *offset) @@ -488,7 +488,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return; } @@ -630,7 +630,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return; } @@ -868,7 +868,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return NULL; } @@ -1001,7 +1001,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From 620b5f637b17f4a6a00876cf4a9a9fd8999a19ca Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Sat, 28 Jan 2023 09:24:23 -0300 Subject: [PATCH 59/92] fix: also treat isset and empty --- Zend/tests/bug80781.phpt | 2 +- ...nstant_expressions_invalid_offset_type_error.phpt | 2 +- Zend/tests/illegal_offset_unset_isset_empty.phpt | 6 +++--- Zend/tests/isset_array.phpt | 4 ++-- Zend/zend_API.c | 7 ++++++- Zend/zend_execute.c | 12 +++++++++++- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 12 ++++++------ ext/opcache/jit/zend_jit_helpers.c | 7 ++++++- ext/spl/tests/iterator_to_array_nonscalar_keys.phpt | 2 +- ext/standard/tests/array/bug68553.phpt | 4 ++-- 11 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Zend/tests/bug80781.phpt b/Zend/tests/bug80781.phpt index eb5109add9f6c..0dc004fb9d74c 100644 --- a/Zend/tests/bug80781.phpt +++ b/Zend/tests/bug80781.phpt @@ -25,7 +25,7 @@ if (isset($array[$data]) or getPlugin($data)) { ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type array in isset or empty in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/constant_expressions_invalid_offset_type_error.phpt b/Zend/tests/constant_expressions_invalid_offset_type_error.phpt index 649c3a325a0c2..1a0ef52dce082 100644 --- a/Zend/tests/constant_expressions_invalid_offset_type_error.phpt +++ b/Zend/tests/constant_expressions_invalid_offset_type_error.phpt @@ -8,7 +8,7 @@ const C2 = [C1, [] => 1]; ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type array on array in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/illegal_offset_unset_isset_empty.phpt b/Zend/tests/illegal_offset_unset_isset_empty.phpt index 9005053e67ed8..9e5818136445d 100644 --- a/Zend/tests/illegal_offset_unset_isset_empty.phpt +++ b/Zend/tests/illegal_offset_unset_isset_empty.phpt @@ -22,6 +22,6 @@ try { ?> --EXPECT-- -Illegal offset type in unset -Illegal offset type in isset or empty -Illegal offset type in isset or empty +Cannot access offset of type array on unset +Cannot access offset of type array in isset or empty +Cannot access offset of type array in isset or empty diff --git a/Zend/tests/isset_array.phpt b/Zend/tests/isset_array.phpt index 4a0652ae39d5f..792483294805d 100644 --- a/Zend/tests/isset_array.phpt +++ b/Zend/tests/isset_array.phpt @@ -46,5 +46,5 @@ bool(false) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(false) -Illegal offset type in isset or empty -Illegal offset type in isset or empty +Cannot access offset of type array in isset or empty +Cannot access offset of type object in isset or empty diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 21e768f0947c3..ba6f801e24c49 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2046,6 +2046,11 @@ ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref) /* } /* }}} */ +ZEND_API void zend_illegal_array_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); +} + ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */ { zval *result; @@ -2074,7 +2079,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) / result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value); break; default: - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(key); result = NULL; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index bb79f6de8aeca..21314face6c2d 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,6 +1455,16 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_empty_or_isset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); +} + +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_unset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s on unset", zend_get_type_by_const(Z_TYPE_P(offset))); +} + static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); @@ -2862,7 +2872,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable ZVAL_UNDEFINED_OP2(); goto str_idx; } else { - zend_type_error("Illegal offset type in isset or empty"); + zend_illegal_empty_or_isset_offset(offset); return NULL; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 6c07924e99cd1..4b7902be7675a 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6571,7 +6571,7 @@ ZEND_VM_C_LABEL(num_index_dim): key = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index_dim); } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 8eb981c07063d..585b9ec6df141 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -25152,7 +25152,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_CONST_HANDL key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -27560,7 +27560,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_TMPVAR_HAND key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -31836,7 +31836,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_CV_HANDLER( key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -43328,7 +43328,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_CONST_HANDLE key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -46928,7 +46928,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_TMPVAR_HANDL key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -52321,7 +52321,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_CV_HANDLER(Z key = ZSTR_EMPTY_ALLOC(); goto str_index_dim; } else { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); } break; } else if (Z_ISREF_P(container)) { diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index d2285cafac370..63280ad09aab0 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,6 +27,11 @@ static ZEND_COLD void undef_result_after_exception(void) { } } +static ZEND_COLD void zend_jit_illegal_empty_or_isset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); +} + static ZEND_COLD void zend_jit_illegal_offset(zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); @@ -732,7 +737,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d hval = 1; goto num_index; default: - zend_type_error("Illegal offset type in isset or empty"); + zend_jit_illegal_empty_or_isset_offset(dim); return 0; } diff --git a/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt index f3460bfccca77..44b4e2a0ebcbb 100644 --- a/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt +++ b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt @@ -21,4 +21,4 @@ try { ?> --EXPECTF-- Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d -Illegal offset type +Cannot access offset of type array on array diff --git a/ext/standard/tests/array/bug68553.phpt b/ext/standard/tests/array/bug68553.phpt index dbb74c7994bb3..7325a68da5413 100644 --- a/ext/standard/tests/array/bug68553.phpt +++ b/ext/standard/tests/array/bug68553.phpt @@ -79,5 +79,5 @@ array(8) { NULL } } -Illegal offset type -Illegal offset type +Cannot access offset of type object on array +Cannot access offset of type array on array From 9b70b6ea85d69ce2d732e11ebeb346d3dff2d46a Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Mon, 30 Jan 2023 21:23:19 -0300 Subject: [PATCH 60/92] fix: change function name for standardization. --- ext/opcache/jit/zend_jit_helpers.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 63280ad09aab0..268427519edb9 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -32,7 +32,7 @@ static ZEND_COLD void zend_jit_illegal_empty_or_isset_offset(const zval *offset) zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); } -static ZEND_COLD void zend_jit_illegal_offset(zval *offset) +static ZEND_COLD void zend_jit_illegal_array_offset(zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } @@ -493,7 +493,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return; } @@ -635,7 +635,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return; } @@ -873,7 +873,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return NULL; } @@ -1006,7 +1006,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From 58d12ad552ff103d6aecdbc88199ff72fba9991d Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 31 Jan 2023 15:25:39 -0300 Subject: [PATCH 61/92] fix: change location of functions and apply in ext/spl. --- Zend/zend_API.c | 12 +++++- Zend/zend_execute.c | 15 ------- ext/spl/spl_array.c | 10 ++--- ext/spl/spl_fixedarray.c | 2 +- ext/spl/tests/ArrayObject_illegal_offset.phpt | 10 ++--- ext/spl/tests/fixedarray_001.phpt | 2 +- ext/spl/tests/fixedarray_002.phpt | 2 +- ext/spl/tests/fixedarray_003.phpt | 40 +++++++++---------- 8 files changed, 44 insertions(+), 49 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index ba6f801e24c49..74ead29e21532 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2046,7 +2046,17 @@ ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref) /* } /* }}} */ -ZEND_API void zend_illegal_array_offset(const zval *offset) +void zend_illegal_empty_or_isset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); +} + +void zend_illegal_unset_offset(const zval *offset) +{ + zend_type_error("Cannot access offset of type %s on unset", zend_get_type_by_const(Z_TYPE_P(offset))); +} + +void zend_illegal_array_offset(const zval *offset) { zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 21314face6c2d..ee4dd16141554 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1455,21 +1455,6 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(v zend_throw_error(NULL, "Cannot use object as array"); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_empty_or_isset_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s in isset or empty", zend_get_type_by_const(Z_TYPE_P(offset))); -} - -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_unset_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on unset", zend_get_type_by_const(Z_TYPE_P(offset))); -} - -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on array", zend_get_type_by_const(Z_TYPE_P(offset))); -} - static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset) { zend_type_error("Cannot access offset of type %s on string", zend_zval_type_name(offset)); diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 4098382c61c17..9b6218f7404f5 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -286,7 +286,7 @@ static zend_result get_hash_key(spl_hash_key *key, spl_array_object *intern, zva ZVAL_DEREF(offset); goto try_again; default: - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); return FAILURE; } @@ -313,7 +313,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object * } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval) : &EG(uninitialized_zval); } @@ -466,7 +466,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); zval_ptr_dtor(value); return; } @@ -502,7 +502,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type in unset"); + zend_illegal_unset_offset(offset); return; } @@ -566,7 +566,7 @@ static bool spl_array_has_dimension_ex(bool check_inherited, zend_object *object spl_hash_key key; if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_type_error("Illegal offset type in isset or empty"); + zend_illegal_empty_or_isset_offset(offset); return 0; } diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 465c649e980aa..b05a5cc3dbcff 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -333,7 +333,7 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ return Z_RES_HANDLE_P(offset); } - zend_type_error("Illegal offset type"); + zend_illegal_array_offset(offset); return 0; } diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt index df25e4fa5e0fa..c21c93781a471 100644 --- a/ext/spl/tests/ArrayObject_illegal_offset.phpt +++ b/ext/spl/tests/ArrayObject_illegal_offset.phpt @@ -32,8 +32,8 @@ try { ?> --EXPECT-- -Illegal offset type -Illegal offset type -Illegal offset type -Illegal offset type in isset or empty -Illegal offset type in unset +Cannot access offset of type array on array +Cannot access offset of type array on array +Cannot access offset of type array on array +Cannot access offset of type array in isset or empty +Cannot access offset of type array on unset diff --git a/ext/spl/tests/fixedarray_001.phpt b/ext/spl/tests/fixedarray_001.phpt index a6ab149c75ca5..c1ebf23b1b07f 100644 --- a/ext/spl/tests/fixedarray_001.phpt +++ b/ext/spl/tests/fixedarray_001.phpt @@ -46,7 +46,7 @@ var_dump($b[0]); ?> --EXPECT-- RuntimeException: Index invalid or out of range -TypeError: Illegal offset type +TypeError: Cannot access offset of type string on array RuntimeException: Index invalid or out of range string(6) "value0" string(6) "value2" diff --git a/ext/spl/tests/fixedarray_002.phpt b/ext/spl/tests/fixedarray_002.phpt index 4f6682e6df3a0..93d10770583ec 100644 --- a/ext/spl/tests/fixedarray_002.phpt +++ b/ext/spl/tests/fixedarray_002.phpt @@ -71,7 +71,7 @@ var_dump(count($a), $a->getSize(), count($a) == $a->getSize()); A::offsetSet RuntimeException: Index invalid or out of range A::offsetGet -TypeError: Illegal offset type +TypeError: Cannot access offset of type string on array A::offsetUnset RuntimeException: Index invalid or out of range A::offsetSet diff --git a/ext/spl/tests/fixedarray_003.phpt b/ext/spl/tests/fixedarray_003.phpt index 277088d04f045..bbd5211dca029 100644 --- a/ext/spl/tests/fixedarray_003.phpt +++ b/ext/spl/tests/fixedarray_003.phpt @@ -168,55 +168,55 @@ try { Write context Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array Read context string(1) "a" string(1) "b" Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d string(1) "c" -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d string(1) "f" string(1) "g" -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array isset() bool(true) bool(true) Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d bool(true) -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(true) bool(true) -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array empty() bool(false) bool(false) Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d bool(false) -Illegal offset type -Illegal offset type +Cannot access offset of type array on array +Cannot access offset of type object on array Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(false) bool(false) -Illegal offset type -Illegal offset type -Illegal offset type +Cannot access offset of type string on array +Cannot access offset of type string on array +Cannot access offset of type string on array From 959f3956def40e8b6e2935c488d9aa58406abbc3 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 62/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 1e77b4e986a8673a3a3f85a1f842359f53c78999 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 63/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 0890300c28fda9ec2cff98189fd393ddddf9e9bb Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 64/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From a3529539c109ba0429811431f7586a9e48f8551a Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 65/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 2a70b36116f06627427e818f07b632a510741f42 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 66/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 7354aa5b13db80e05b12f0971446eabcea0e4f75 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 67/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 90360f4022ae5cd865c4c57f785f8c70fe36019b Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 68/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From ce0ecc95f8e137266d1fd5db9a2797b71f945fe7 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 69/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 0776d35aad6a6f37207b7a6f0bd66c5e1de1e5eb Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 70/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 4503ff7d5c31921a77597b8049528cb04ac70019 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 71/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 1232aaf2d638b2c298b7fe82c26ac761ceba37ad Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Wed, 25 Jan 2023 20:31:01 -0300 Subject: [PATCH 72/92] inform the type in the array displacement error message. --- Zend/zend_execute.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index ee4dd16141554..9d808c1725da2 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2323,6 +2323,12 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval case IS_TRUE: value->lval = 1; return IS_LONG; + case IS_ARRAY: + zend_type_error("Illegal offset type: cannot be of type array"); + return IS_ARRAY; + case IS_OBJECT: + zend_type_error("Illegal offset type: cannot be of type object"); + return IS_OBJECT; default: zend_illegal_array_offset(dim); return IS_NULL; @@ -2397,6 +2403,12 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv case IS_TRUE: value->lval = 1; return IS_LONG; + case IS_ARRAY: + zend_type_error("Illegal offset type: cannot be of type array"); + return IS_ARRAY; + case IS_OBJECT: + zend_type_error("Illegal offset type: cannot be of type object"); + return IS_OBJECT; default: zend_illegal_array_offset(dim); return IS_NULL; From 4f3991a5ecd8828fefb49c72a63bf7b06c4ec12b Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 08:06:29 -0300 Subject: [PATCH 73/92] inform the type in the array displacement error message. --- Zend/zend_execute.c | 16 ++-------------- ext/opcache/tests/opt/inference_002.phpt | 1 + 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 9d808c1725da2..bc498f9721fd8 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2323,14 +2323,8 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval case IS_TRUE: value->lval = 1; return IS_LONG; - case IS_ARRAY: - zend_type_error("Illegal offset type: cannot be of type array"); - return IS_ARRAY; - case IS_OBJECT: - zend_type_error("Illegal offset type: cannot be of type object"); - return IS_OBJECT; default: - zend_illegal_array_offset(dim); + zend_illegal_offset(); return IS_NULL; } } @@ -2403,14 +2397,8 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv case IS_TRUE: value->lval = 1; return IS_LONG; - case IS_ARRAY: - zend_type_error("Illegal offset type: cannot be of type array"); - return IS_ARRAY; - case IS_OBJECT: - zend_type_error("Illegal offset type: cannot be of type object"); - return IS_OBJECT; default: - zend_illegal_array_offset(dim); + zend_illegal_offset(); return IS_NULL; } } diff --git a/ext/opcache/tests/opt/inference_002.phpt b/ext/opcache/tests/opt/inference_002.phpt index 3d8c69d054e5d..0ac2f93627e89 100644 --- a/ext/opcache/tests/opt/inference_002.phpt +++ b/ext/opcache/tests/opt/inference_002.phpt @@ -13,3 +13,4 @@ Fatal error: Uncaught TypeError: Cannot access offset of type array on array in Stack trace: #0 {main} thrown in %sinference_002.php on line 2 + From e6c4efec135fa1cae6bfa9c6dc827e673f4793ed Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 74/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 9d436161b668ad9f450431cad42fc440369259a4 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 75/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 15d21322c48f06a510a69f3b214cb7df11a961fc Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 76/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From c62de156abc6829f6ea2da0640dbe33bd46b6fd6 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 77/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 1bf8ce7f28a1cd5ac4d2cfeaa3a67ddeb76711b9 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 27 Jan 2023 19:32:25 +0100 Subject: [PATCH 78/92] Prevent dtor of generator in suspended fiber (#10462) Generators that suspended a fiber should not be dtor because they will be executed during the fiber dtor. Fiber dtor throws an exception in the fiber's context in order to unwind and execute finally blocks, which will also properly dtor the generator. Fixes GH-9916 --- Zend/tests/gh9916-001.phpt | 27 ++++++++++++++++++ Zend/tests/gh9916-002.phpt | 21 ++++++++++++++ Zend/tests/gh9916-003.phpt | 36 ++++++++++++++++++++++++ Zend/tests/gh9916-004.phpt | 26 +++++++++++++++++ Zend/tests/gh9916-005.phpt | 25 +++++++++++++++++ Zend/tests/gh9916-006.phpt | 37 +++++++++++++++++++++++++ Zend/tests/gh9916-007.phpt | 57 ++++++++++++++++++++++++++++++++++++++ Zend/tests/gh9916-008.phpt | 47 +++++++++++++++++++++++++++++++ Zend/tests/gh9916-009.phpt | 35 +++++++++++++++++++++++ Zend/tests/gh9916-010.phpt | 34 +++++++++++++++++++++++ Zend/tests/gh9916-011.phpt | 41 +++++++++++++++++++++++++++ Zend/zend_generators.h | 1 + 12 files changed, 387 insertions(+) create mode 100644 Zend/tests/gh9916-001.phpt create mode 100644 Zend/tests/gh9916-002.phpt create mode 100644 Zend/tests/gh9916-003.phpt create mode 100644 Zend/tests/gh9916-004.phpt create mode 100644 Zend/tests/gh9916-005.phpt create mode 100644 Zend/tests/gh9916-006.phpt create mode 100644 Zend/tests/gh9916-007.phpt create mode 100644 Zend/tests/gh9916-008.phpt create mode 100644 Zend/tests/gh9916-009.phpt create mode 100644 Zend/tests/gh9916-010.phpt create mode 100644 Zend/tests/gh9916-011.phpt diff --git a/Zend/tests/gh9916-001.phpt b/Zend/tests/gh9916-001.phpt new file mode 100644 index 0000000000000..3e518807238bc --- /dev/null +++ b/Zend/tests/gh9916-001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally diff --git a/Zend/tests/gh9916-002.phpt b/Zend/tests/gh9916-002.phpt new file mode 100644 index 0000000000000..6f0b81cf3e91a --- /dev/null +++ b/Zend/tests/gh9916-002.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-003.phpt b/Zend/tests/gh9916-003.phpt new file mode 100644 index 0000000000000..c4bfb815118bc --- /dev/null +++ b/Zend/tests/gh9916-003.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally (inner) +Finally diff --git a/Zend/tests/gh9916-004.phpt b/Zend/tests/gh9916-004.phpt new file mode 100644 index 0000000000000..1a51a841e8bb6 --- /dev/null +++ b/Zend/tests/gh9916-004.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-005.phpt b/Zend/tests/gh9916-005.phpt new file mode 100644 index 0000000000000..f84c756919cd0 --- /dev/null +++ b/Zend/tests/gh9916-005.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +send($fiber); + $gen->current(); +}); +$fiber->start(); + +$gen = null; +$fiber = null; +gc_collect_cycles(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-006.phpt b/Zend/tests/gh9916-006.phpt new file mode 100644 index 0000000000000..28c57105c7b1f --- /dev/null +++ b/Zend/tests/gh9916-006.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Fiber return\n"; +}); +$fiber->start(); +$fiber->resume(); +$gen->next(); +$gen->current(); +?> +==DONE== +--EXPECT-- +Before suspend +After suspend +Fiber return +Before exit diff --git a/Zend/tests/gh9916-007.phpt b/Zend/tests/gh9916-007.phpt new file mode 100644 index 0000000000000..e1ec3fb19f32b --- /dev/null +++ b/Zend/tests/gh9916-007.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== +Finally (iterator) +Finally diff --git a/Zend/tests/gh9916-008.phpt b/Zend/tests/gh9916-008.phpt new file mode 100644 index 0000000000000..84521d69e2120 --- /dev/null +++ b/Zend/tests/gh9916-008.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Not executed"; +}); +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-009.phpt b/Zend/tests/gh9916-009.phpt new file mode 100644 index 0000000000000..75643d871dea0 --- /dev/null +++ b/Zend/tests/gh9916-009.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- + new stdClass]; + print "Not executed\n"; + } +})(); +$fiber = new Fiber(function() use ($gen, &$fiber) { + $gen->current(); + print "Not executed\n"; +}); +$fiber->start(); +?> +==DONE== +--EXPECTF-- +Before suspend +==DONE== +Finally + +Fatal error: Uncaught Error: Cannot use "yield from" in a force-closed generator in %s:%d +Stack trace: +#0 [internal function]: {closure}() +#1 %s(%d): Generator->current() +#2 [internal function]: {closure}() +#3 {main} + thrown in %s on line %d diff --git a/Zend/tests/gh9916-010.phpt b/Zend/tests/gh9916-010.phpt new file mode 100644 index 0000000000000..d3a841d7ceb31 --- /dev/null +++ b/Zend/tests/gh9916-010.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +current(); + print "Before next\n"; + $gen->next(); + print "Not executed\n"; +}); + +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before current +Before yield +Before yield 2 +Before next +Before suspend +==DONE== diff --git a/Zend/tests/gh9916-011.phpt b/Zend/tests/gh9916-011.phpt new file mode 100644 index 0000000000000..05fa884c29337 --- /dev/null +++ b/Zend/tests/gh9916-011.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) +--FILE-- +next(); + } +})(); + +$fiber = new Fiber(function () use ($gen, &$fiber) { + print "Before current\n"; + $gen->current(); + print "Before next\n"; + $gen->next(); + print "Not executed\n"; +}); + +$fiber->start(); +?> +==DONE== +--EXPECT-- +Before current +Before yield +Before yield 2 +Before next +Before suspend +==DONE== diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h index 17b25a99b87c1..4ccc42b92f668 100644 --- a/Zend/zend_generators.h +++ b/Zend/zend_generators.h @@ -92,6 +92,7 @@ static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1; static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2; static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4; static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8; +static const zend_uchar ZEND_GENERATOR_IN_FIBER = 0x10; void zend_register_generator_ce(void); ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution); From fc6b26a5bed9f36d8200ef85236a0b97944f89c6 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 79/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From b9d6b6b6225edb07651d6d4f17939e945ca1f9a4 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 80/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From f7bb931dc409ebf6e26ba008f5edec56dded4b83 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 81/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 7bc258352a3bdab95d198b325c98d117909cfe01 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 82/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 71540eacc86dcc05e3751a79023ac0e4ef5d2637 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 16:54:14 -0300 Subject: [PATCH 83/92] inform the type in the array displacement error message. --- Zend/zend_execute.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index bc498f9721fd8..977b6bd5eca99 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2324,7 +2324,7 @@ static zend_never_inline zend_uchar slow_index_convert(HashTable *ht, const zval value->lval = 1; return IS_LONG; default: - zend_illegal_offset(); + zend_illegal_array_offset(dim); return IS_NULL; } } @@ -2398,7 +2398,7 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv value->lval = 1; return IS_LONG; default: - zend_illegal_offset(); + zend_illegal_array_offset(); return IS_NULL; } } From 3fd18aafdbe138721978570ee3b4dc6e03aed16b Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:09:36 -0300 Subject: [PATCH 84/92] Revert "Prevent dtor of generator in suspended fiber (#10462)" This reverts commit aeca4d222bd241e9cfd5e24a0d35a256b904e11f. --- Zend/tests/gh9916-001.phpt | 27 ------------------ Zend/tests/gh9916-002.phpt | 21 -------------- Zend/tests/gh9916-003.phpt | 36 ------------------------ Zend/tests/gh9916-004.phpt | 26 ----------------- Zend/tests/gh9916-005.phpt | 25 ----------------- Zend/tests/gh9916-006.phpt | 37 ------------------------- Zend/tests/gh9916-007.phpt | 57 -------------------------------------- Zend/tests/gh9916-008.phpt | 47 ------------------------------- Zend/tests/gh9916-009.phpt | 35 ----------------------- Zend/tests/gh9916-010.phpt | 34 ----------------------- Zend/tests/gh9916-011.phpt | 41 --------------------------- Zend/zend_generators.c | 4 +-- Zend/zend_generators.h | 1 - 13 files changed, 1 insertion(+), 390 deletions(-) delete mode 100644 Zend/tests/gh9916-001.phpt delete mode 100644 Zend/tests/gh9916-002.phpt delete mode 100644 Zend/tests/gh9916-003.phpt delete mode 100644 Zend/tests/gh9916-004.phpt delete mode 100644 Zend/tests/gh9916-005.phpt delete mode 100644 Zend/tests/gh9916-006.phpt delete mode 100644 Zend/tests/gh9916-007.phpt delete mode 100644 Zend/tests/gh9916-008.phpt delete mode 100644 Zend/tests/gh9916-009.phpt delete mode 100644 Zend/tests/gh9916-010.phpt delete mode 100644 Zend/tests/gh9916-011.phpt diff --git a/Zend/tests/gh9916-001.phpt b/Zend/tests/gh9916-001.phpt deleted file mode 100644 index 3e518807238bc..0000000000000 --- a/Zend/tests/gh9916-001.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Bug GH-9916 001 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally diff --git a/Zend/tests/gh9916-002.phpt b/Zend/tests/gh9916-002.phpt deleted file mode 100644 index 6f0b81cf3e91a..0000000000000 --- a/Zend/tests/gh9916-002.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug GH-9916 002 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-003.phpt b/Zend/tests/gh9916-003.phpt deleted file mode 100644 index c4bfb815118bc..0000000000000 --- a/Zend/tests/gh9916-003.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -Bug GH-9916 003 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally (inner) -Finally diff --git a/Zend/tests/gh9916-004.phpt b/Zend/tests/gh9916-004.phpt deleted file mode 100644 index 1a51a841e8bb6..0000000000000 --- a/Zend/tests/gh9916-004.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug GH-9916 004 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-005.phpt b/Zend/tests/gh9916-005.phpt deleted file mode 100644 index f84c756919cd0..0000000000000 --- a/Zend/tests/gh9916-005.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Bug GH-9916 005 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -send($fiber); - $gen->current(); -}); -$fiber->start(); - -$gen = null; -$fiber = null; -gc_collect_cycles(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-006.phpt b/Zend/tests/gh9916-006.phpt deleted file mode 100644 index 28c57105c7b1f..0000000000000 --- a/Zend/tests/gh9916-006.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -Bug GH-9916 006 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Fiber return\n"; -}); -$fiber->start(); -$fiber->resume(); -$gen->next(); -$gen->current(); -?> -==DONE== ---EXPECT-- -Before suspend -After suspend -Fiber return -Before exit diff --git a/Zend/tests/gh9916-007.phpt b/Zend/tests/gh9916-007.phpt deleted file mode 100644 index e1ec3fb19f32b..0000000000000 --- a/Zend/tests/gh9916-007.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== -Finally (iterator) -Finally diff --git a/Zend/tests/gh9916-008.phpt b/Zend/tests/gh9916-008.phpt deleted file mode 100644 index 84521d69e2120..0000000000000 --- a/Zend/tests/gh9916-008.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -Bug GH-9916 008 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Not executed"; -}); -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-009.phpt b/Zend/tests/gh9916-009.phpt deleted file mode 100644 index 75643d871dea0..0000000000000 --- a/Zend/tests/gh9916-009.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -Bug GH-9916 009 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- - new stdClass]; - print "Not executed\n"; - } -})(); -$fiber = new Fiber(function() use ($gen, &$fiber) { - $gen->current(); - print "Not executed\n"; -}); -$fiber->start(); -?> -==DONE== ---EXPECTF-- -Before suspend -==DONE== -Finally - -Fatal error: Uncaught Error: Cannot use "yield from" in a force-closed generator in %s:%d -Stack trace: -#0 [internal function]: {closure}() -#1 %s(%d): Generator->current() -#2 [internal function]: {closure}() -#3 {main} - thrown in %s on line %d diff --git a/Zend/tests/gh9916-010.phpt b/Zend/tests/gh9916-010.phpt deleted file mode 100644 index d3a841d7ceb31..0000000000000 --- a/Zend/tests/gh9916-010.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -Bug GH-9916 010 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -current(); - print "Before next\n"; - $gen->next(); - print "Not executed\n"; -}); - -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before current -Before yield -Before yield 2 -Before next -Before suspend -==DONE== diff --git a/Zend/tests/gh9916-011.phpt b/Zend/tests/gh9916-011.phpt deleted file mode 100644 index 05fa884c29337..0000000000000 --- a/Zend/tests/gh9916-011.phpt +++ /dev/null @@ -1,41 +0,0 @@ ---TEST-- -Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes) ---FILE-- -next(); - } -})(); - -$fiber = new Fiber(function () use ($gen, &$fiber) { - print "Before current\n"; - $gen->current(); - print "Before next\n"; - $gen->next(); - print "Not executed\n"; -}); - -$fiber->start(); -?> -==DONE== ---EXPECT-- -Before current -Before yield -Before yield 2 -Before next -Before suspend -==DONE== diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index ed2bd039708e9..958d9784c9458 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -749,8 +749,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ } /* Resume execution */ - generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING - | (EG(active_fiber) ? ZEND_GENERATOR_IN_FIBER : 0); + generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING; if (!ZEND_OBSERVER_ENABLED) { zend_execute_ex(generator->execute_data); } else { @@ -801,7 +800,6 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */ goto try_again; } - generator->flags &= ~ZEND_GENERATOR_IN_FIBER; orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT; } /* }}} */ diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h index 4ccc42b92f668..17b25a99b87c1 100644 --- a/Zend/zend_generators.h +++ b/Zend/zend_generators.h @@ -92,7 +92,6 @@ static const zend_uchar ZEND_GENERATOR_CURRENTLY_RUNNING = 0x1; static const zend_uchar ZEND_GENERATOR_FORCED_CLOSE = 0x2; static const zend_uchar ZEND_GENERATOR_AT_FIRST_YIELD = 0x4; static const zend_uchar ZEND_GENERATOR_DO_INIT = 0x8; -static const zend_uchar ZEND_GENERATOR_IN_FIBER = 0x10; void zend_register_generator_ce(void); ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution); From 84f9c49dea4d83619d370078d6c1f0437771ff8f Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 27 Jan 2023 17:44:48 -0300 Subject: [PATCH 85/92] fix: handle JIT helper. --- ext/opcache/jit/zend_jit_helpers.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 268427519edb9..1744c3f2d18a3 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -493,7 +493,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_array_offset(dim); + zend_jit_illegal_offset(); undef_result_after_exception(); return; } @@ -635,7 +635,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_array_offset(dim); + zend_jit_illegal_offset(); undef_result_after_exception(); return; } @@ -737,7 +737,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d hval = 1; goto num_index; default: - zend_jit_illegal_empty_or_isset_offset(dim); + zend_type_error("Illegal offset type in isset or empty"); return 0; } @@ -873,7 +873,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_array_offset(dim); + zend_jit_illegal_offset(); undef_result_after_exception(); return NULL; } @@ -1006,7 +1006,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_array_offset(dim); + zend_jit_illegal_offset(); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From 8dba14a9762eb8b4530692c50c5001ec4af244a3 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Sat, 28 Jan 2023 09:24:23 -0300 Subject: [PATCH 86/92] fix: also treat isset and empty --- Zend/zend_API.c | 2 +- Zend/zend_execute.c | 4 ++-- ext/opcache/jit/zend_jit_helpers.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 74ead29e21532..e2045b755882b 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2089,7 +2089,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) / result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value); break; default: - zend_illegal_array_offset(key); + zend_type_error("Illegal offset type"); result = NULL; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 977b6bd5eca99..c58da4b00e450 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2398,7 +2398,7 @@ static zend_never_inline zend_uchar slow_index_convert_w(HashTable *ht, const zv value->lval = 1; return IS_LONG; default: - zend_illegal_array_offset(); + zend_illegal_array_offset(dim); return IS_NULL; } } @@ -2857,7 +2857,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable ZVAL_UNDEFINED_OP2(); goto str_idx; } else { - zend_illegal_empty_or_isset_offset(offset); + zend_type_error("Illegal offset type in isset or empty"); return NULL; } } diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 1744c3f2d18a3..89817446e88b9 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -493,7 +493,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return; } @@ -635,7 +635,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return; } @@ -873,7 +873,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); return NULL; } @@ -1006,7 +1006,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(); + zend_jit_illegal_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From 72097982541e850caab5079a0deb93de7d6fb236 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Mon, 30 Jan 2023 21:23:19 -0300 Subject: [PATCH 87/92] fix: change function name for standardization. --- ext/opcache/jit/zend_jit_helpers.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 89817446e88b9..1e6b39da26464 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -493,7 +493,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return; } @@ -635,7 +635,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return; } @@ -873,7 +873,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); return NULL; } @@ -1006,7 +1006,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_jit_illegal_offset(dim); + zend_jit_illegal_array_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA From 1c1d822f20bdc3cd2736fc01d70b13d976a3eac6 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 88/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From f983b02f039587aeaee534f1b6bb55ed6c5a31d6 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 89/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From dca199d1214e39078326a1e6cb402667606d3033 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Fri, 16 Dec 2022 18:06:06 -0300 Subject: [PATCH 90/92] chore: unnecessary parentheses. --- ext/json/json.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index 2de78e3dabc2e..f37ff5552226f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,8 +303,7 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - - if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { + if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -315,7 +314,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From e9a048aedd05486988e92cf55cbd0f6b78a95a09 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 17 Jan 2023 16:17:02 -0300 Subject: [PATCH 91/92] Revert "chore: unnecessary parentheses." This reverts commit 91227c5ac5d0040a74dfe3e3c25549fb642e4ab9. --- ext/json/json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/json/json.c b/ext/json/json.c index f37ff5552226f..2de78e3dabc2e 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -303,7 +303,8 @@ PHP_FUNCTION(json_validate) Z_PARAM_LONG(options) ZEND_PARSE_PARAMETERS_END(); - if (options != 0 && options != PHP_JSON_INVALID_UTF8_IGNORE) { + + if ((options != 0) && (options != PHP_JSON_INVALID_UTF8_IGNORE)) { zend_argument_value_error(3, "must be a valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)"); RETURN_THROWS(); } @@ -314,7 +315,7 @@ PHP_FUNCTION(json_validate) } JSON_G(error_code) = PHP_JSON_ERROR_NONE; - + if (depth <= 0) { zend_argument_value_error(2, "must be greater than 0"); RETURN_THROWS(); From 14b6e343f7ddf355ab0ea91d2a307c8b232ec2b8 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 31 Jan 2023 16:12:29 -0300 Subject: [PATCH 92/92] fix: test --- Zend/zend_compile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index c2d53bd943ec7..4582e53083f16 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -8752,6 +8752,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ default: zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type"); break; + } } else if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), value)) { zval_ptr_dtor_nogc(value);