From d46355540420c8c13772ea4479320db8048f9b47 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Sat, 4 Feb 2023 12:06:03 -0300 Subject: [PATCH 1/4] fix: report type on prompt: Illegal offset type --- 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 +- Zend/tests/bug80781.phpt | 2 +- ...expressions_invalid_offset_type_error.phpt | 2 +- Zend/tests/gh8821.phpt | 2 +- .../illegal_offset_unset_isset_empty.phpt | 6 +-- .../tests/init_array_illegal_offset_type.phpt | 2 +- Zend/tests/isset_array.phpt | 4 +- Zend/tests/offset_array.phpt | 4 +- Zend/zend_API.c | 12 ++++- Zend/zend_execute.c | 22 +++++++--- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 44 +++++++++---------- ext/opcache/jit/zend_jit_helpers.c | 19 +++++--- 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 | 4 +- ext/spl/spl_array.c | 25 ++++++++--- ext/spl/spl_fixedarray.c | 7 ++- 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 ++++++++--------- .../iterator_to_array_nonscalar_keys.phpt | 2 +- .../tests/array/array_key_exists.phpt | 2 +- .../array/array_key_exists_variation1.phpt | 4 +- ext/standard/tests/array/bug68553.phpt | 4 +- tests/classes/tostring_001.phpt | 2 +- 32 files changed, 149 insertions(+), 104 deletions(-) diff --git a/Zend/tests/036.phpt b/Zend/tests/036.phpt index 8f74bccc075f..4037d3d0e3d2 100644 --- a/Zend/tests/036.phpt +++ b/Zend/tests/036.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type +Cannot access offset of type object on array diff --git a/Zend/tests/038.phpt b/Zend/tests/038.phpt index e55757bbcd41..4f822a6f5a15 100644 --- a/Zend/tests/038.phpt +++ b/Zend/tests/038.phpt @@ -11,4 +11,4 @@ try { ?> --EXPECT-- -Illegal offset type +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 0a2ea94c552d..02e709818669 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 +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 -Illegal offset type +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 4fce25291bcb..0d34e2be0fc1 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: 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 906f58144b41..0593eacfd6c4 100644 --- a/Zend/tests/bug79947.phpt +++ b/Zend/tests/bug79947.phpt @@ -12,6 +12,6 @@ try { var_dump($array); ?> --EXPECT-- -Illegal offset type +Cannot access offset of type array on array array(0) { } diff --git a/Zend/tests/bug80781.phpt b/Zend/tests/bug80781.phpt index eb5109add9f6..0dc004fb9d74 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 649c3a325a0c..1a0ef52dce08 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/gh8821.phpt b/Zend/tests/gh8821.phpt index 8f1b3ceff34a..e6abf5c1c4f1 100644 --- a/Zend/tests/gh8821.phpt +++ b/Zend/tests/gh8821.phpt @@ -15,7 +15,7 @@ new Bravo(); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: Illegal offset type in %sgh8821.php:8 +Fatal error: Uncaught TypeError: Cannot access offset of type object on array in %sgh8821.php:8 Stack trace: #0 %sgh8821.php(11): [constant expression]() #1 {main} diff --git a/Zend/tests/illegal_offset_unset_isset_empty.phpt b/Zend/tests/illegal_offset_unset_isset_empty.phpt index 9005053e67ed..9e5818136445 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/init_array_illegal_offset_type.phpt b/Zend/tests/init_array_illegal_offset_type.phpt index 2243ca2905ea..2e5a0401d6e4 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 access offset of type object on array diff --git a/Zend/tests/isset_array.phpt b/Zend/tests/isset_array.phpt index 4a0652ae39d5..792483294805 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/tests/offset_array.phpt b/Zend/tests/offset_array.phpt index 0109950cde84..e44244511fcf 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) -Illegal offset type -Illegal offset type +Cannot access offset of type object on array +Cannot access offset of type array on array Done diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 21e768f0947c..905687a00b95 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -407,6 +407,16 @@ 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; @@ -2074,7 +2084,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 a28aef62ab3e..522a3efcf05d 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1466,9 +1466,19 @@ 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_unset_offset(const zval *offset) { - zend_type_error("Illegal offset type"); + 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_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) @@ -2340,7 +2350,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; } } @@ -2414,7 +2424,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(dim); return IS_NULL; } } @@ -2873,7 +2883,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; } } @@ -2996,7 +3006,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_array_offset(key); return 0; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index ca062b9512ac..c956479e4e43 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6589,7 +6589,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 d9dd9b589024..8e167ea4fd77 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -7353,7 +7353,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -9684,7 +9684,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -10607,7 +10607,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -12067,7 +12067,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20093,7 +20093,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -20533,7 +20533,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -20994,7 +20994,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -21394,7 +21394,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25161,7 +25161,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -25253,7 +25253,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)) { @@ -27569,7 +27569,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -27661,7 +27661,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)) { @@ -29590,7 +29590,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -31845,7 +31845,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -31937,7 +31937,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)) { @@ -43355,7 +43355,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -43447,7 +43447,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)) { @@ -46973,7 +46973,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } zval_ptr_dtor_nogc(EX_VAR(opline->op2.var)); @@ -47065,7 +47065,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)) { @@ -48878,7 +48878,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52384,7 +52384,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_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } @@ -52476,7 +52476,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 261b456a4fc3..998557211749 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,9 +27,14 @@ 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_array_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_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) @@ -488,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_array_offset(dim); undef_result_after_exception(); return; } @@ -630,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_array_offset(dim); undef_result_after_exception(); return; } @@ -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; } @@ -868,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_array_offset(dim); undef_result_after_exception(); return NULL; } @@ -1001,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_array_offset(dim); undef_result_after_exception(); if (EG(opline_before_exception) && (EG(opline_before_exception)+1)->opcode == ZEND_OP_DATA diff --git a/ext/opcache/tests/jit/assign_dim_002.phpt b/ext/opcache/tests/jit/assign_dim_002.phpt index 3f713a6c6a6a..83b4bfdec787 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 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 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 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 a533cbe9c283..731a2e96420a 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 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 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 ea3fff88f1e4..d9302b8fd04c 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: 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 70412426c2fc..3d8c69d054e5 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: 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 \ No newline at end of file + thrown in %sinference_002.php on line 2 diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 4098382c61c1..485f23769693 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -89,6 +89,21 @@ 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 on 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); } @@ -286,7 +301,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"); + spl_array_illegal_offset(offset); return FAILURE; } @@ -313,7 +328,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"); + spl_array_illegal_offset(offset); return (type == BP_VAR_W || type == BP_VAR_RW) ? &EG(error_zval) : &EG(uninitialized_zval); } @@ -466,7 +481,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"); + spl_array_illegal_offset(offset); zval_ptr_dtor(value); return; } @@ -502,7 +517,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"); + spl_array_illegal_unset_offset(offset); return; } @@ -566,7 +581,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"); + spl_array_illegal_empty_or_isset_offset(offset); return 0; } diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 465c649e980a..291744fce0d9 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -83,6 +83,11 @@ 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; @@ -333,7 +338,7 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ return Z_RES_HANDLE_P(offset); } - zend_type_error("Illegal offset type"); + spl_fixedarray_illegal_offset(offset); return 0; } diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt index df25e4fa5e0f..d6af13cf9e04 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 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 on unset diff --git a/ext/spl/tests/fixedarray_001.phpt b/ext/spl/tests/fixedarray_001.phpt index a6ab149c75ca..35a7a9cf1772 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 FixedArray 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 4f6682e6df3a..940d5996f5db 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 FixedArray 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 277088d04f04..d246561c1b7e 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 FixedArray +Cannot access offset of type object on FixedArray 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 FixedArray +Cannot access offset of type string on FixedArray +Cannot access offset of type string on FixedArray 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 FixedArray +Cannot access offset of type object on FixedArray 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 FixedArray +Cannot access offset of type string on FixedArray +Cannot access offset of type string on FixedArray 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 FixedArray +Cannot access offset of type object on FixedArray 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 FixedArray +Cannot access offset of type string on FixedArray +Cannot access offset of type string on FixedArray 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 FixedArray +Cannot access offset of type object on FixedArray 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 FixedArray +Cannot access offset of type string on FixedArray +Cannot access offset of type string on FixedArray diff --git a/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt b/ext/spl/tests/iterator_to_array_nonscalar_keys.phpt index f3460bfccca7..44b4e2a0ebcb 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/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt index d6f9ca13de71..8cc2f9c5207c 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 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 3a410258bb99..eb35d1bfae0c 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 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 access offset of type object on array -- Iteration 18 -- bool(false) diff --git a/ext/standard/tests/array/bug68553.phpt b/ext/standard/tests/array/bug68553.phpt index dbb74c7994bb..7325a68da541 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 diff --git a/tests/classes/tostring_001.phpt b/tests/classes/tostring_001.phpt index abf41f97cdac..ddbe4d152dde 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 access offset of type object on array ====test8==== test2::__toString() string(9) "Converted" From 53fb7806a95e32d63ba705181d5675fc53f72f4e Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Mon, 6 Feb 2023 20:35:29 -0300 Subject: [PATCH 2/4] fix: report type on prompt: Illegal offset type --- Zend/tests/illegal_offset_unset_isset_empty.phpt | 2 +- Zend/zend_execute.c | 2 +- ext/opcache/jit/zend_jit_helpers.c | 2 +- ext/spl/spl_array.c | 2 +- ext/spl/tests/ArrayObject_illegal_offset.phpt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Zend/tests/illegal_offset_unset_isset_empty.phpt b/Zend/tests/illegal_offset_unset_isset_empty.phpt index 9e5818136445..a09613748281 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 on unset +Cannot access offset of type array in 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/zend_execute.c b/Zend/zend_execute.c index 522a3efcf05d..206c32315f66 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1468,7 +1468,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_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))); + 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) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 998557211749..2e76f3f7f479 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -27,7 +27,7 @@ static ZEND_COLD void undef_result_after_exception(void) { } } -static ZEND_COLD void zend_jit_illegal_array_offset(zval *offset) +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))); } diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 485f23769693..9504f9e26368 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -101,7 +101,7 @@ static void spl_array_illegal_empty_or_isset_offset(const zval *offset) static void spl_array_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))); + 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) { /* {{{ */ diff --git a/ext/spl/tests/ArrayObject_illegal_offset.phpt b/ext/spl/tests/ArrayObject_illegal_offset.phpt index d6af13cf9e04..08353c704c6f 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 on unset +Cannot access offset of type array in unset From 58e12c5c72c6599c03f9db39800a3121e6268aa9 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Mon, 6 Feb 2023 20:49:32 -0300 Subject: [PATCH 3/4] fix: run Zend/zend_vm_gen.php. --- Zend/zend_vm_def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c956479e4e43..1b39e46c380a 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6073,7 +6073,7 @@ ZEND_VM_C_LABEL(num_index): str = ZSTR_EMPTY_ALLOC(); ZEND_VM_C_GOTO(str_index); } else { - zend_illegal_offset(); + zend_illegal_array_offset(offset); zval_ptr_dtor_nogc(expr_ptr); } FREE_OP2(); From 75aa3e86d5803b028486d8beacf901e126282025 Mon Sep 17 00:00:00 2001 From: Marcos Marcolin Date: Tue, 7 Feb 2023 17:10:21 -0300 Subject: [PATCH 4/4] ci: change to trigger CI. --- ext/spl/spl_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 9504f9e26368..337c2b9902fb 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -12,7 +12,7 @@ +----------------------------------------------------------------------+ | Authors: Marcus Boerger | +----------------------------------------------------------------------+ - */ +*/ #ifdef HAVE_CONFIG_H # include "config.h"