From 0d43c0797a9193b943e2f7a5397509e15e717d84 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 8 Feb 2023 12:55:21 +0000 Subject: [PATCH 1/6] Use common function for container offset type errors This merges all usages of emiting an offset TypeError into a new ZEND_API function zend_illegal_container_offset(const char* container, const zval *offset, int type); Where the container should represent the type on which the access is attempted (e.g. string, array) The offset zval that is used, where the error message will display its type The type of access, which should be a BP_VAR_* constant, to get special message for isset/empty/unset --- Zend/tests/036.phpt | 2 +- Zend/tests/038.phpt | 2 +- Zend/tests/assign_dim_obj_null_return.phpt | 4 +- Zend/tests/bug24773.phpt | 2 +- Zend/tests/gh8821.phpt | 2 +- .../tests/init_array_illegal_offset_type.phpt | 2 +- Zend/tests/isset_array.phpt | 2 +- Zend/tests/offset_array.phpt | 2 +- Zend/zend.c | 18 ++++++++ Zend/zend.h | 2 + Zend/zend_API.c | 12 +---- Zend/zend_execute.c | 36 ++++----------- Zend/zend_vm_def.h | 4 +- Zend/zend_vm_execute.h | 44 +++++++++---------- ext/opcache/jit/zend_jit_helpers.c | 42 ++++++------------ ext/opcache/tests/jit/assign_dim_002.phpt | 2 +- ext/spl/spl_array.c | 26 +++-------- ext/spl/spl_fixedarray.c | 7 +-- ext/spl/tests/fixedarray_001.phpt | 2 +- ext/spl/tests/fixedarray_002.phpt | 2 +- ext/spl/tests/fixedarray_003.phpt | 42 +++++++++--------- .../array/array_key_exists_variation1.phpt | 2 +- ext/standard/tests/array/bug68553.phpt | 2 +- tests/classes/tostring_001.phpt | 2 +- 24 files changed, 110 insertions(+), 153 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 4037d3d0e3d2..8958237b0eb8 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Cannot access offset of type object on array +Cannot access offset of type Closure on array diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index 4f822a6f5a15..8b6441e3c25a 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Cannot access offset of type object on array +Cannot access offset of type Closure on array diff --git a/Zend/tests/assign_dim_obj_null_return.phpt b/Zend/tests/assign_dim_obj_null_return.phpt index 02e709818669..e2b7f20a0c07 100644 --- a/Zend/tests/assign_dim_obj_null_return.phpt +++ b/Zend/tests/assign_dim_obj_null_return.phpt @@ -73,11 +73,11 @@ test(); --EXPECT-- Cannot add element to the array as the next element is already occupied Cannot access offset of type array on array -Cannot access offset of type object on array +Cannot access offset of type stdClass on array Cannot use a scalar value as an array Cannot add element to the array as the next element is already occupied Cannot access offset of type array on array -Cannot access offset of type object on array +Cannot access offset of type stdClass 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/bug24773.phpt b/Zend/tests/bug24773.phpt index 4c73fd0dd00f..73b163b968ce 100644 --- a/Zend/tests/bug24773.phpt +++ b/Zend/tests/bug24773.phpt @@ -6,7 +6,7 @@ Bug #24773 (unset() of integers treated as arrays causes a crash) unset($array["lvl1"]["lvl2"]["b"]); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Cannot access offset of type string on string in %s:%d +Fatal error: Uncaught TypeError: Cannot access offset of type string in unset in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/gh8821.phpt b/Zend/tests/gh8821.phpt index e6abf5c1c4f1..7588239fc83b 100644 --- a/Zend/tests/gh8821.phpt +++ b/Zend/tests/gh8821.phpt @@ -15,7 +15,7 @@ new Bravo(); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Cannot access offset of type object on array in %sgh8821.php:8 +Fatal error: Uncaught TypeError: Cannot access offset of type Alpha on array in %sgh8821.php:8 Stack trace: #0 %sgh8821.php(11): [constant expression]() #1 {main} diff --git a/Zend/tests/init_array_illegal_offset_type.phpt b/Zend/tests/init_array_illegal_offset_type.phpt index 2e5a0401d6e4..ee41c0217ad7 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-- -Cannot access offset of type object on array +Cannot access offset of type stdClass on array diff --git a/Zend/tests/isset_array.phpt b/Zend/tests/isset_array.phpt index 792483294805..dfa3fdef51dd 100644 --- a/Zend/tests/isset_array.phpt +++ b/Zend/tests/isset_array.phpt @@ -47,4 +47,4 @@ bool(false) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d bool(false) Cannot access offset of type array in isset or empty -Cannot access offset of type object in isset or empty +Cannot access offset of type stdClass in isset or empty diff --git a/Zend/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index e44244511fcf..368ec7a020e1 100644 --- a/Zend/tests/offset_array.phpt +++ b/Zend/tests/offset_array.phpt @@ -48,6 +48,6 @@ int(1) Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d int(%d) -Cannot access offset of type object on array +Cannot access offset of type stdClass on array Cannot access offset of type array on array Done diff --git a/Zend/zend.c b/Zend/zend.c index bbddd4597042..17458aae57a5 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1719,6 +1719,24 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c } /* }}} */ +/* type should be one of the BP_VAR_* constants, only special messages happen for isset/empty and unset */ +ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, const zval *offset, int type) +{ + switch (type) { + case BP_VAR_IS: + zend_type_error("Cannot access offset of type %s in isset or empty", + zend_zval_type_name(offset)); + return; + case BP_VAR_UNSET: + zend_type_error("Cannot access offset of type %s in unset", zend_zval_type_name(offset)); + return; + default: + zend_type_error("Cannot access offset of type %s on %s", + zend_zval_type_name(offset), container); + return; + } +} + ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) /* {{{ */ { va_list va; diff --git a/Zend/zend.h b/Zend/zend.h index fd21cbfeb93c..0f035532d7cc 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -357,6 +357,8 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); +/* type should be one of the BP_VAR_* constants, only special messages happen for isset/empty and unset */ +ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, const zval *offset, int type); ZEND_COLD void zenderror(const char *error); diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 61f15fec0c88..6661764c2775 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -407,16 +407,6 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_en } /* }}} */ -ZEND_API ZEND_COLD 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_COLD 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))); -} - ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...) /* {{{ */ { va_list va; @@ -2112,7 +2102,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_illegal_container_offset("array", key, BP_VAR_W); result = NULL; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index caaedce98a85..802678842ad7 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1506,26 +1506,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_unset_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s in 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_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_string_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on string", zend_zval_type_name(offset)); -} - static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) { obj->handlers->write_dimension(obj, dim, value); @@ -1651,7 +1631,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type } return offset; } - zend_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, type); return 0; } case IS_UNDEF: @@ -1667,7 +1647,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type dim = Z_REFVAL_P(dim); goto try_again; default: - zend_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, type); return 0; } @@ -2390,7 +2370,7 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d value->lval = 1; return IS_LONG; default: - zend_illegal_array_offset(dim); + zend_illegal_container_offset("array", dim, BP_VAR_R); return IS_NULL; } } @@ -2464,7 +2444,7 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval value->lval = 1; return IS_LONG; default: - zend_illegal_array_offset(dim); + zend_illegal_container_offset("array", dim, BP_VAR_W); return IS_NULL; } } @@ -2762,7 +2742,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z ZVAL_NULL(result); return; } - zend_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, BP_VAR_R); ZVAL_NULL(result); return; } @@ -2801,7 +2781,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z dim = Z_REFVAL_P(dim); goto try_string_offset; default: - zend_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, BP_VAR_R); ZVAL_NULL(result); return; } @@ -2923,7 +2903,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_illegal_container_offset("array", offset, BP_VAR_IS); return NULL; } } @@ -3046,7 +3026,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_array_offset(key); + zend_illegal_container_offset("array", key, BP_VAR_R); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 7e86b29c6b4f..b91396c8c7e9 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6098,7 +6098,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); @@ -6610,7 +6610,7 @@ ZEND_VM_C_LABEL(num_index_dim): key = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index_dim); } else { - zend_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 14e3a5aca2a2..3751c62c5122 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7371,7 +7371,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -9690,7 +9690,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10613,7 +10613,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -12063,7 +12063,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -20063,7 +20063,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -20507,7 +20507,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20968,7 +20968,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -21372,7 +21372,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -25188,7 +25188,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -25280,7 +25280,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_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -27627,7 +27627,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -27719,7 +27719,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_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -29705,7 +29705,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -32015,7 +32015,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -32107,7 +32107,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_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -43690,7 +43690,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -43782,7 +43782,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_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -47330,7 +47330,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -47422,7 +47422,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_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -49292,7 +49292,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -52791,7 +52791,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_array_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -52883,7 +52883,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_illegal_unset_offset(offset); + zend_illegal_container_offset("array", offset, BP_VAR_UNSET); } 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 41c7e14a804c..ef27c875c696 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,21 +27,6 @@ static ZEND_COLD void undef_result_after_exception(void) { } } -static ZEND_COLD void zend_jit_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_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_string_offset(zval *offset) -{ - zend_type_error("Cannot access offset of type %s on string", zend_zval_value_name(offset)); -} - static zend_never_inline zend_function* ZEND_FASTCALL _zend_jit_init_func_run_time_cache(zend_op_array *op_array) /* {{{ */ { void **run_time_cache; @@ -493,7 +478,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_illegal_container_offset("array", dim, BP_VAR_R); undef_result_after_exception(); return; } @@ -635,7 +620,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_illegal_container_offset("array", dim, BP_VAR_IS); undef_result_after_exception(); return; } @@ -737,7 +722,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_illegal_container_offset("array", dim, BP_VAR_IS); return 0; } @@ -873,7 +858,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_illegal_container_offset("array", dim, BP_VAR_RW); undef_result_after_exception(); return NULL; } @@ -1006,7 +991,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_illegal_container_offset("array", dim, BP_VAR_R); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA @@ -1029,7 +1014,8 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim return retval; } -static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int type*/) +/* type is one of the BP_VAR_* constants */ +static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type) { zend_long offset; @@ -1049,7 +1035,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int typ } return offset; } - zend_jit_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, BP_VAR_R); return 0; } case IS_UNDEF: @@ -1065,7 +1051,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int typ dim = Z_REFVAL_P(dim); goto try_again; default: - zend_jit_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, type); return 0; } @@ -1103,7 +1089,7 @@ static zend_string* ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zend_string *s if (!(GC_FLAGS(str) & IS_STR_INTERNED)) { GC_ADDREF(str); } - offset = zend_check_string_offset(dim/*, BP_VAR_R*/); + offset = zend_check_string_offset(dim, BP_VAR_R); if (!(GC_FLAGS(str) & IS_STR_INTERNED) && UNEXPECTED(GC_DELREF(str) == 0)) { zend_string *ret = zend_jit_fetch_dim_str_offset(str, offset); zend_string_efree(str); @@ -1140,7 +1126,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva dim = Z_REFVAL_P(dim); goto try_string_offset; default: - zend_jit_illegal_string_offset(dim); + zend_illegal_container_offset("string", dim, BP_VAR_IS); break; } @@ -1242,7 +1228,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, /* The string may be destroyed while throwing the notice. * Temporarily increase the refcount to detect this situation. */ GC_ADDREF(s); - offset = zend_check_string_offset(dim/*, BP_VAR_W*/); + offset = zend_check_string_offset(dim, BP_VAR_W); if (UNEXPECTED(GC_DELREF(s) == 0)) { zend_string_efree(s); if (result) { @@ -1418,7 +1404,7 @@ static zend_always_inline void ZEND_FASTCALL zend_jit_fetch_dim_obj_helper(zval zend_throw_error(NULL, "[] operator not supported for strings"); } else { if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) { - zend_check_string_offset(dim/*, BP_VAR_RW*/); + zend_check_string_offset(dim, BP_VAR_RW); } zend_wrong_string_offset_error(); } @@ -1606,7 +1592,7 @@ static void ZEND_FASTCALL zend_jit_assign_dim_op_helper(zval *container, zval *d zend_throw_error(NULL, "[] operator not supported for strings"); } else { if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) { - zend_check_string_offset(dim/*, BP_VAR_RW*/); + zend_check_string_offset(dim, BP_VAR_RW); } zend_wrong_string_offset_error(); } diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 83b4bfdec787..743ca1bf093e 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) } } -Cannot access offset of type object on array +Cannot access offset of type Closure on array array(1) { [0]=> array(2) { diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 1ef0c48d272d..4fb13b7ad4c3 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -95,21 +95,6 @@ static inline HashTable **spl_array_get_hash_table_ptr(spl_array_object* intern) } /* }}} */ -static void spl_array_illegal_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on ArrayObject", zend_get_type_by_const(Z_TYPE_P(offset))); -} - -static void spl_array_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 void spl_array_illegal_unset_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s in unset", zend_get_type_by_const(Z_TYPE_P(offset))); -} - static inline HashTable *spl_array_get_hash_table(spl_array_object* intern) { /* {{{ */ return *spl_array_get_hash_table_ptr(intern); } @@ -269,6 +254,8 @@ static void spl_hash_key_release(spl_hash_key *key) { } } +/* This function does not throw any exceptions for illegal offsets, calls to + * zend_illegal_container_offset(); need to be made if the return value is FAILURE */ static zend_result get_hash_key(spl_hash_key *key, spl_array_object *intern, zval *offset) { key->release_key = false; @@ -309,7 +296,6 @@ static zend_result get_hash_key(spl_hash_key *key, spl_array_object *intern, zva ZVAL_DEREF(offset); goto try_again; default: - spl_array_illegal_offset(offset); return FAILURE; } @@ -336,7 +322,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object * } if (get_hash_key(&key, intern, offset) == FAILURE) { - spl_array_illegal_offset(offset); + zend_illegal_container_offset("ArrayObject", offset, type); return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval) : &EG(uninitialized_zval); } @@ -512,7 +498,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - spl_array_illegal_offset(offset); + zend_illegal_container_offset("ArrayObject", offset, BP_VAR_W); zval_ptr_dtor(value); return; } @@ -553,7 +539,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - spl_array_illegal_unset_offset(offset); + zend_illegal_container_offset("ArrayObject", offset, BP_VAR_UNSET); return; } @@ -623,7 +609,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) { - spl_array_illegal_empty_or_isset_offset(offset); + zend_illegal_container_offset("ArrayObject", offset, BP_VAR_IS); return 0; } diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 574b06fc4e93..84492f78c524 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -83,11 +83,6 @@ static bool spl_fixedarray_empty(spl_fixedarray *array) return true; } -static void spl_fixedarray_illegal_offset(const zval *offset) -{ - zend_type_error("Cannot access offset of type %s on FixedArray", zend_get_type_by_const(Z_TYPE_P(offset))); -} - static void spl_fixedarray_default_ctor(spl_fixedarray *array) { array->size = 0; @@ -338,7 +333,7 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ return Z_RES_HANDLE_P(offset); } - spl_fixedarray_illegal_offset(offset); + zend_illegal_container_offset("SplFixedArray", offset, BP_VAR_R); return 0; } diff --git a/ext/spl/tests/fixedarray_001.phpt b/ext/spl/tests/fixedarray_001.phpt index 35a7a9cf1772..0683555934d5 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: Cannot access offset of type string on FixedArray +TypeError: Cannot access offset of type string on SplFixedArray 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 940d5996f5db..0ee2dcb8ba11 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: Cannot access offset of type string on FixedArray +TypeError: Cannot access offset of type string on SplFixedArray 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 d246561c1b7e..cca9ac07e9f7 100644 --- a/ext/spl/tests/fixedarray_003.phpt +++ b/ext/spl/tests/fixedarray_003.phpt @@ -1,5 +1,5 @@ --TEST-- -SPL: FixedArray: Non integer offset handling +SPL: SplFixedArray: Non integer offset handling --FILE-- Date: Wed, 31 May 2023 15:59:31 +0100 Subject: [PATCH 2/6] Use zend_string for container variable Also pass called CE --- Zend/zend.c | 4 +-- Zend/zend.h | 2 +- Zend/zend_API.c | 2 +- Zend/zend_execute.c | 16 +++++------ Zend/zend_vm_def.h | 4 +-- Zend/zend_vm_execute.h | 44 +++++++++++++++--------------- ext/opcache/jit/zend_jit_helpers.c | 16 +++++------ ext/spl/spl_array.c | 15 +++++----- ext/spl/spl_fixedarray.c | 3 +- 9 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Zend/zend.c b/Zend/zend.c index 17458aae57a5..ac3d5f1855dd 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1720,7 +1720,7 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c /* }}} */ /* type should be one of the BP_VAR_* constants, only special messages happen for isset/empty and unset */ -ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, const zval *offset, int type) +ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *container, const zval *offset, int type) { switch (type) { case BP_VAR_IS: @@ -1732,7 +1732,7 @@ ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, con return; default: zend_type_error("Cannot access offset of type %s on %s", - zend_zval_type_name(offset), container); + zend_zval_type_name(offset), ZSTR_VAL(container)); return; } } diff --git a/Zend/zend.h b/Zend/zend.h index 0f035532d7cc..94440530f3b3 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -358,7 +358,7 @@ ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_ ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2); /* type should be one of the BP_VAR_* constants, only special messages happen for isset/empty and unset */ -ZEND_API ZEND_COLD void zend_illegal_container_offset(const char *container, const zval *offset, int type); +ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *container, const zval *offset, int type); ZEND_COLD void zenderror(const char *error); diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 6661764c2775..2bd236a26262 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2102,7 +2102,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_container_offset("array", key, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), key, BP_VAR_W); result = NULL; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 802678842ad7..be072bb45cd9 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1631,7 +1631,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type } return offset; } - zend_illegal_container_offset("string", dim, type); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, type); return 0; } case IS_UNDEF: @@ -1647,7 +1647,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type dim = Z_REFVAL_P(dim); goto try_again; default: - zend_illegal_container_offset("string", dim, type); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, type); return 0; } @@ -2370,7 +2370,7 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d value->lval = 1; return IS_LONG; default: - zend_illegal_container_offset("array", dim, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_R); return IS_NULL; } } @@ -2444,7 +2444,7 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval value->lval = 1; return IS_LONG; default: - zend_illegal_container_offset("array", dim, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_W); return IS_NULL; } } @@ -2742,7 +2742,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z ZVAL_NULL(result); return; } - zend_illegal_container_offset("string", dim, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); ZVAL_NULL(result); return; } @@ -2781,7 +2781,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z dim = Z_REFVAL_P(dim); goto try_string_offset; default: - zend_illegal_container_offset("string", dim, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); ZVAL_NULL(result); return; } @@ -2903,7 +2903,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable ZVAL_UNDEFINED_OP2(); goto str_idx; } else { - zend_illegal_container_offset("array", offset, BP_VAR_IS); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_IS); return NULL; } } @@ -3026,7 +3026,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_container_offset("array", key, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), key, BP_VAR_R); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index b91396c8c7e9..b2468445e965 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6098,7 +6098,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); @@ -6610,7 +6610,7 @@ ZEND_VM_C_LABEL(num_index_dim): key = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index_dim); } else { - zend_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 3751c62c5122..94e31270fc14 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7371,7 +7371,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -9690,7 +9690,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10613,7 +10613,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -12063,7 +12063,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -20063,7 +20063,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -20507,7 +20507,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20968,7 +20968,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -21372,7 +21372,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -25188,7 +25188,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -25280,7 +25280,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_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -27627,7 +27627,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -27719,7 +27719,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_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -29705,7 +29705,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -32015,7 +32015,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -32107,7 +32107,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_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -43690,7 +43690,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -43782,7 +43782,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_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -47330,7 +47330,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -47422,7 +47422,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_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } break; } else if (Z_ISREF_P(container)) { @@ -49292,7 +49292,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -52791,7 +52791,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_container_offset("array", offset, BP_VAR_W); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); zval_ptr_dtor_nogc(expr_ptr); } @@ -52883,7 +52883,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_illegal_container_offset("array", offset, BP_VAR_UNSET); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } 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 ef27c875c696..f9541bd7087d 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -478,7 +478,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, hval = 1; goto num_index; default: - zend_illegal_container_offset("array", dim, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_R); undef_result_after_exception(); return; } @@ -620,7 +620,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_illegal_container_offset("array", dim, BP_VAR_IS); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_IS); undef_result_after_exception(); return; } @@ -722,7 +722,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d hval = 1; goto num_index; default: - zend_illegal_container_offset("array", dim, BP_VAR_IS); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_IS); return 0; } @@ -858,7 +858,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di hval = 1; goto num_index; default: - zend_illegal_container_offset("array", dim, BP_VAR_RW); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_RW); undef_result_after_exception(); return NULL; } @@ -991,7 +991,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim hval = 1; goto num_index; default: - zend_illegal_container_offset("array", dim, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_R); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA @@ -1035,7 +1035,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type) } return offset; } - zend_illegal_container_offset("string", dim, BP_VAR_R); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); return 0; } case IS_UNDEF: @@ -1051,7 +1051,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type) dim = Z_REFVAL_P(dim); goto try_again; default: - zend_illegal_container_offset("string", dim, type); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, type); return 0; } @@ -1126,7 +1126,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva dim = Z_REFVAL_P(dim); goto try_string_offset; default: - zend_illegal_container_offset("string", dim, BP_VAR_IS); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_IS); break; } diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 4fb13b7ad4c3..0373f5a7820e 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -306,7 +306,8 @@ static zend_result get_hash_key(spl_hash_key *key, spl_array_object *intern, zva return SUCCESS; } -static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *intern, zval *offset, int type) /* {{{ */ +static zval *spl_array_get_dimension_ptr(bool check_inherited, spl_array_object *intern, const zend_string *ce_name, + zval *offset, int type) /* {{{ */ { zval *retval; spl_hash_key key; @@ -322,7 +323,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object * } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_illegal_container_offset("ArrayObject", offset, type); + zend_illegal_container_offset(ce_name, offset, type); return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval) : &EG(uninitialized_zval); } @@ -424,7 +425,7 @@ static zval *spl_array_read_dimension_ex(int check_inherited, zend_object *objec } } - ret = spl_array_get_dimension_ptr(check_inherited, intern, offset, type); + ret = spl_array_get_dimension_ptr(check_inherited, intern, object->ce->name, offset, type); /* When in a write context, * ZE has to be fooled into thinking this is in a reference set @@ -498,7 +499,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_illegal_container_offset("ArrayObject", offset, BP_VAR_W); + zend_illegal_container_offset(object->ce->name, offset, BP_VAR_W); zval_ptr_dtor(value); return; } @@ -539,7 +540,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec } if (get_hash_key(&key, intern, offset) == FAILURE) { - zend_illegal_container_offset("ArrayObject", offset, BP_VAR_UNSET); + zend_illegal_container_offset(object->ce->name, offset, BP_VAR_UNSET); return; } @@ -609,7 +610,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_illegal_container_offset("ArrayObject", offset, BP_VAR_IS); + zend_illegal_container_offset(object->ce->name, offset, BP_VAR_IS); return 0; } @@ -847,7 +848,7 @@ static zval *spl_array_get_property_ptr_ptr(zend_object *object, zend_string *na return NULL; } ZVAL_STR(&member, name); - return spl_array_get_dimension_ptr(1, intern, &member, type); + return spl_array_get_dimension_ptr(1, intern, object->ce->name, &member, type); } return zend_std_get_property_ptr_ptr(object, name, type, cache_slot); } /* }}} */ diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 84492f78c524..bffdbbebcedc 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -333,7 +333,8 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ return Z_RES_HANDLE_P(offset); } - zend_illegal_container_offset("SplFixedArray", offset, BP_VAR_R); + /* Use SplFixedArray name from the CE */ + zend_illegal_container_offset(spl_ce_SplFixedArray->name, offset, BP_VAR_R); return 0; } From d445bf6f0ee8f6806152f6f8079b5a1ad363a243 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 31 May 2023 16:11:01 +0100 Subject: [PATCH 3/6] Consistent error messages for unsetting a string offset --- Zend/tests/bug24773.phpt | 2 +- Zend/zend.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Zend/tests/bug24773.phpt b/Zend/tests/bug24773.phpt index 73b163b968ce..f1845fa46a68 100644 --- a/Zend/tests/bug24773.phpt +++ b/Zend/tests/bug24773.phpt @@ -6,7 +6,7 @@ Bug #24773 (unset() of integers treated as arrays causes a crash) unset($array["lvl1"]["lvl2"]["b"]); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Cannot access offset of type string in unset in %s:%d +Fatal error: Uncaught Error: Cannot unset string offsets in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/zend.c b/Zend/zend.c index ac3d5f1855dd..b1215f57394c 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1728,7 +1728,12 @@ ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *contain zend_zval_type_name(offset)); return; case BP_VAR_UNSET: - zend_type_error("Cannot access offset of type %s in unset", zend_zval_type_name(offset)); + /* Consistent error for when trying to unset a string offset */ + if (zend_string_equals(container, ZSTR_KNOWN(ZEND_STR_STRING))) { + zend_throw_error(NULL, "Cannot unset string offsets"); + } else { + zend_type_error("Cannot access offset of type %s in unset", zend_zval_type_name(offset)); + } return; default: zend_type_error("Cannot access offset of type %s on %s", From 38d3bfc311bc3b6f7ea25fcb373adc9632320744 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 5 Jun 2023 15:22:57 +0100 Subject: [PATCH 4/6] More consistent unset error message --- Zend/tests/illegal_offset_unset_isset_empty.phpt | 2 +- Zend/zend.c | 2 +- ext/spl/tests/ArrayObject_illegal_offset.phpt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/tests/illegal_offset_unset_isset_empty.phpt b/Zend/tests/illegal_offset_unset_isset_empty.phpt index a09613748281..ee837f0b6143 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-- -Cannot access offset of type array in unset +Cannot unset offset of type array on array Cannot access offset of type array in isset or empty Cannot access offset of type array in isset or empty diff --git a/Zend/zend.c b/Zend/zend.c index b1215f57394c..0e3cfb4381fa 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1732,7 +1732,7 @@ ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *contain if (zend_string_equals(container, ZSTR_KNOWN(ZEND_STR_STRING))) { zend_throw_error(NULL, "Cannot unset string offsets"); } else { - zend_type_error("Cannot access offset of type %s in unset", zend_zval_type_name(offset)); + zend_type_error("Cannot unset offset of type %s on %s", zend_zval_type_name(offset), ZSTR_VAL(container)); } return; default: diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt index 08353c704c6f..a2803e472966 100644 --- a/ext/spl/tests/ArrayObject_illegal_offset.phpt +++ b/ext/spl/tests/ArrayObject_illegal_offset.phpt @@ -36,4 +36,4 @@ Cannot access offset of type array on ArrayObject Cannot access offset of type array on ArrayObject Cannot access offset of type array on ArrayObject Cannot access offset of type array in isset or empty -Cannot access offset of type array in unset +Cannot unset offset of type array on ArrayObject From 4e587493ac2a2e0752567091ab54d43b9c1fe5a5 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 5 Jun 2023 15:37:24 +0100 Subject: [PATCH 5/6] Use specialized VM functions again --- Zend/zend_execute.c | 36 ++++++++++++++++++++++++++-------- Zend/zend_vm_def.h | 4 ++-- Zend/zend_vm_execute.h | 44 +++++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index be072bb45cd9..ab3ab03e5097 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1506,6 +1506,26 @@ 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_array_offset_access(const zval *offset) +{ + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_RW); +} + +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_isset(const zval *offset) +{ + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_IS); +} + +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_unset(const zval *offset) +{ + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); +} + +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset_access(const zval *offset) +{ + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, BP_VAR_RW); +} + static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) { obj->handlers->write_dimension(obj, dim, value); @@ -1631,7 +1651,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type } return offset; } - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, type); + zend_illegal_string_offset_access(dim); return 0; } case IS_UNDEF: @@ -1647,7 +1667,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type dim = Z_REFVAL_P(dim); goto try_again; default: - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, type); + zend_illegal_string_offset_access(dim); return 0; } @@ -2370,7 +2390,7 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d value->lval = 1; return IS_LONG; default: - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_R); + zend_illegal_array_offset_access(dim); return IS_NULL; } } @@ -2444,7 +2464,7 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval value->lval = 1; return IS_LONG; default: - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), dim, BP_VAR_W); + zend_illegal_array_offset_access(dim); return IS_NULL; } } @@ -2742,7 +2762,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z ZVAL_NULL(result); return; } - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); + zend_illegal_string_offset_access(dim); ZVAL_NULL(result); return; } @@ -2781,7 +2801,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z dim = Z_REFVAL_P(dim); goto try_string_offset; default: - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); + zend_illegal_string_offset_access(dim); ZVAL_NULL(result); return; } @@ -2903,7 +2923,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable ZVAL_UNDEFINED_OP2(); goto str_idx; } else { - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_IS); + zend_illegal_array_offset_isset(offset); return NULL; } } @@ -3026,7 +3046,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable str = ZSTR_EMPTY_ALLOC(); goto str_key; } else { - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), key, BP_VAR_R); + zend_illegal_array_offset_access(key); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index b2468445e965..437aa4b0c3b5 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6098,7 +6098,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); @@ -6610,7 +6610,7 @@ ZEND_VM_C_LABEL(num_index_dim): key = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index_dim); } else { - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 94e31270fc14..8ec2f6946007 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7371,7 +7371,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -9690,7 +9690,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10613,7 +10613,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -12063,7 +12063,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20063,7 +20063,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20507,7 +20507,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20968,7 +20968,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -21372,7 +21372,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25188,7 +25188,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25280,7 +25280,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_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -27627,7 +27627,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -27719,7 +27719,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_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -29705,7 +29705,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -32015,7 +32015,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -32107,7 +32107,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_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -43690,7 +43690,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -43782,7 +43782,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_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -47330,7 +47330,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -47422,7 +47422,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_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { @@ -49292,7 +49292,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52791,7 +52791,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_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_W); + zend_illegal_array_offset_access(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52883,7 +52883,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_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); + zend_illegal_array_offset_unset(offset); } break; } else if (Z_ISREF_P(container)) { From c41efe0916c1f35116d6f7218b596b42b6beab2f Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 5 Jun 2023 16:34:22 +0100 Subject: [PATCH 6/6] Pass access type again to string offset error function --- Zend/zend_execute.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index ab3ab03e5097..29631504d5f9 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1521,9 +1521,9 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_array_offset_ zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), offset, BP_VAR_UNSET); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset_access(const zval *offset) +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_string_offset(const zval *offset, int type) { - zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, BP_VAR_RW); + zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), offset, type); } static zend_never_inline void zend_assign_to_object_dim(zend_object *obj, zval *dim, zval *value OPLINE_DC EXECUTE_DATA_DC) @@ -1651,7 +1651,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type } return offset; } - zend_illegal_string_offset_access(dim); + zend_illegal_string_offset(dim, type); return 0; } case IS_UNDEF: @@ -1667,7 +1667,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type dim = Z_REFVAL_P(dim); goto try_again; default: - zend_illegal_string_offset_access(dim); + zend_illegal_string_offset(dim, type); return 0; } @@ -2762,7 +2762,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z ZVAL_NULL(result); return; } - zend_illegal_string_offset_access(dim); + zend_illegal_string_offset(dim, BP_VAR_R); ZVAL_NULL(result); return; } @@ -2801,7 +2801,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z dim = Z_REFVAL_P(dim); goto try_string_offset; default: - zend_illegal_string_offset_access(dim); + zend_illegal_string_offset(dim, BP_VAR_R); ZVAL_NULL(result); return; }