Skip to content

Commit 21663e8

Browse files
committed
Use zend_check_string_offset()
1 parent 52cb0f4 commit 21663e8

8 files changed

+87
-81
lines changed

Zend/tests/bug31098.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ echo $simpleString["0"] === "B"?"ok\n":"bug\n";
6161
bool(false)
6262
bool(false)
6363
bool(false)
64-
Illegal offset type string for container of type string in isset or empty
65-
Illegal offset type string for container of type string in isset or empty
66-
Illegal offset type string for container of type string in isset or empty
64+
Cannot access offset of type string on string
65+
Cannot access offset of type string on string
66+
Cannot access offset of type string on string
6767
ok
68-
Illegal offset type string for container of type string in isset or empty
68+
Cannot access offset of type string on string
6969
ok
7070
ok
7171
ok

Zend/tests/bug60362.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ if (empty($arr['exists'][1][0])) {
7070
echo "DONE";
7171
?>
7272
--EXPECT--
73-
Illegal offset type string for container of type string in isset or empty
73+
Cannot access offset of type string on string
7474
sub-key 1 is set: string(1) "o"
7575
-------------------
7676
sub-sub-key 'sub_sub' is not set.
7777
sub-sub-key 0 is set: string(1) "o"
7878
-------------------
79-
Illegal offset type string for container of type string in isset or empty
79+
Cannot access offset of type string on string
8080
sub-key 1 is not empty: string(1) "o"
8181
-------------------
8282
sub-sub-key 'sub_sub' is empty.

Zend/tests/bug69889.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ string(1) "t"
2323
string(7) "default"
2424
string(7) "default"
2525
string(7) "default"
26-
Illegal offset type string for container of type string in isset or empty
26+
Cannot access offset of type string on string

Zend/tests/bug81160.phpt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ try {
3838
echo $e->getMessage(), "\n";
3939
}
4040

41+
// TODO handle ??
42+
4143
?>
4244
--EXPECT--
43-
Illegal offset type stdClass for container of type string in isset or empty
44-
Illegal offset type stdClass for container of type string in isset or empty
45-
Illegal offset type array for container of type string in isset or empty
46-
Illegal offset type array for container of type string in isset or empty
47-
Illegal offset type array for container of type string in isset or empty
48-
Illegal offset type array for container of type string in isset or empty
45+
Cannot access offset of type stdClass on string
46+
Cannot access offset of type stdClass on string
47+
Cannot access offset of type array on string
48+
Cannot access offset of type array on string
49+
Cannot access offset of type array on string
50+
Cannot access offset of type array on string

Zend/tests/empty_str_offset.phpt

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,57 +119,69 @@ bool(true)
119119
bool(false)
120120
bool(false)
121121
bool(true)
122-
Illegal offset type string for container of type string in isset or empty
123-
Illegal offset type string for container of type string in isset or empty
124-
Illegal offset type string for container of type string in isset or empty
122+
Cannot access offset of type string on string
123+
Cannot access offset of type string on string
124+
125+
Warning: Illegal string offset "3 and a half" in %s on line %d
126+
bool(false)
125127
- string variable ---
126128
bool(false)
127129
bool(true)
128130
bool(false)
129131
bool(false)
130132
bool(true)
131-
Illegal offset type string for container of type string in isset or empty
132-
Illegal offset type string for container of type string in isset or empty
133-
Illegal offset type string for container of type string in isset or empty
133+
Cannot access offset of type string on string
134+
Cannot access offset of type string on string
135+
136+
Warning: Illegal string offset "3 and a half" in %s on line %d
137+
bool(false)
134138
- bool ---
139+
140+
Warning: String offset cast occurred in %s on line %d
135141
bool(false)
142+
143+
Warning: String offset cast occurred in %s on line %d
136144
bool(false)
145+
146+
Warning: String offset cast occurred in %s on line %d
137147
bool(true)
138148
- null ---
149+
150+
Warning: String offset cast occurred in %s on line %d
139151
bool(false)
140152
- double ---
141153

142-
Deprecated: Implicit conversion from float -1.1 to int loses precision in %s on line %d
154+
Warning: String offset cast occurred in %s on line %d
143155
bool(false)
144156

145-
Deprecated: Implicit conversion from float -10.5 to int loses precision in %s on line %d
157+
Warning: String offset cast occurred in %s on line %d
146158
bool(true)
147159

148-
Deprecated: Implicit conversion from float -4.1 to int loses precision in %s on line %d
160+
Warning: String offset cast occurred in %s on line %d
149161
bool(true)
150162

151-
Deprecated: Implicit conversion from float -0.8 to int loses precision in %s on line %d
163+
Warning: String offset cast occurred in %s on line %d
152164
bool(false)
153165

154-
Deprecated: Implicit conversion from float -0.1 to int loses precision in %s on line %d
166+
Warning: String offset cast occurred in %s on line %d
155167
bool(false)
156168

157-
Deprecated: Implicit conversion from float 0.2 to int loses precision in %s on line %d
169+
Warning: String offset cast occurred in %s on line %d
158170
bool(false)
159171

160-
Deprecated: Implicit conversion from float 0.9 to int loses precision in %s on line %d
172+
Warning: String offset cast occurred in %s on line %d
161173
bool(false)
162174

163-
Deprecated: Implicit conversion from float 3.141592653589793 to int loses precision in %s on line %d
175+
Warning: String offset cast occurred in %s on line %d
164176
bool(false)
165177

166-
Deprecated: Implicit conversion from float 100.5001 to int loses precision in %s on line %d
178+
Warning: String offset cast occurred in %s on line %d
167179
bool(true)
168180
- array ---
169-
Illegal offset type array for container of type string in isset or empty
170-
Illegal offset type array for container of type string in isset or empty
181+
Cannot access offset of type array on string
182+
Cannot access offset of type array on string
171183
- object ---
172-
Illegal offset type stdClass for container of type string in isset or empty
184+
Cannot access offset of type stdClass on string
173185
- resource ---
174-
Illegal offset type resource for container of type string in isset or empty
186+
Cannot access offset of type resource on string
175187
done

Zend/tests/isset_str_offset.phpt

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,54 +116,66 @@ bool(false)
116116
bool(true)
117117
bool(true)
118118
bool(true)
119-
Illegal offset type string for container of type string in isset or empty
120-
Illegal offset type string for container of type string in isset or empty
121-
Illegal offset type string for container of type string in isset or empty
119+
Cannot access offset of type string on string
120+
Cannot access offset of type string on string
121+
122+
Warning: Illegal string offset "3 and a half" in %s on line %d
123+
bool(true)
122124
- string variable ---
123125
bool(true)
124126
bool(false)
125127
bool(true)
126128
bool(true)
127129
bool(true)
128-
Illegal offset type string for container of type string in isset or empty
129-
Illegal offset type string for container of type string in isset or empty
130-
Illegal offset type string for container of type string in isset or empty
130+
Cannot access offset of type string on string
131+
Cannot access offset of type string on string
132+
133+
Warning: Illegal string offset "3 and a half" in %s on line %d
134+
bool(true)
131135
- bool ---
136+
137+
Warning: String offset cast occurred in %s on line %d
132138
bool(true)
139+
140+
Warning: String offset cast occurred in %s on line %d
133141
bool(true)
142+
143+
Warning: String offset cast occurred in %s on line %d
134144
bool(false)
135145
- null ---
146+
147+
Warning: String offset cast occurred in %s on line %d
136148
bool(true)
137149
- double ---
138150

139-
Deprecated: Implicit conversion from float -1.1 to int loses precision in %s on line %d
151+
Warning: String offset cast occurred in %s on line %d
140152
bool(true)
141153

142-
Deprecated: Implicit conversion from float -10.5 to int loses precision in %s on line %d
154+
Warning: String offset cast occurred in %s on line %d
143155
bool(false)
144156

145-
Deprecated: Implicit conversion from float -0.8 to int loses precision in %s on line %d
157+
Warning: String offset cast occurred in %s on line %d
146158
bool(true)
147159

148-
Deprecated: Implicit conversion from float -0.1 to int loses precision in %s on line %d
160+
Warning: String offset cast occurred in %s on line %d
149161
bool(true)
150162

151-
Deprecated: Implicit conversion from float 0.2 to int loses precision in %s on line %d
163+
Warning: String offset cast occurred in %s on line %d
152164
bool(true)
153165

154-
Deprecated: Implicit conversion from float 0.9 to int loses precision in %s on line %d
166+
Warning: String offset cast occurred in %s on line %d
155167
bool(true)
156168

157-
Deprecated: Implicit conversion from float 3.141592653589793 to int loses precision in %s on line %d
169+
Warning: String offset cast occurred in %s on line %d
158170
bool(true)
159171

160-
Deprecated: Implicit conversion from float 100.5001 to int loses precision in %s on line %d
172+
Warning: String offset cast occurred in %s on line %d
161173
bool(false)
162174
- array ---
163-
Illegal offset type array for container of type string in isset or empty
164-
Illegal offset type array for container of type string in isset or empty
175+
Cannot access offset of type array on string
176+
Cannot access offset of type array on string
165177
- object ---
166-
Illegal offset type stdClass for container of type string in isset or empty
178+
Cannot access offset of type stdClass on string
167179
- resource ---
168-
Illegal offset type resource for container of type string in isset or empty
180+
Cannot access offset of type resource on string
169181
done

Zend/zend_execute.c

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,12 +2531,6 @@ ZEND_API void zend_fetch_dimension_const(zval *result, zval *container, zval *di
25312531
zend_fetch_dimension_address_read(result, container, dim, IS_TMP_VAR, type, 0, 0 NO_EXECUTE_DATA_CC);
25322532
}
25332533

2534-
static zend_never_inline void zend_invalid_offset_type_isset_empty(zval *container, zval *offset)
2535-
{
2536-
zend_type_error("Illegal offset type %s for container of type %s in isset or empty",
2537-
zend_zval_type_name(offset), zend_zval_type_name(container));
2538-
}
2539-
25402534
static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable *ht, zval *offset EXECUTE_DATA_DC)
25412535
{
25422536
zend_ulong hval;
@@ -2590,19 +2584,12 @@ static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container,
25902584
return 0;
25912585
}
25922586
} else {
2593-
/*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/
2594-
ZVAL_DEREF(offset);
2595-
/*}*/
2596-
// Leading numeric strings can be read...
2597-
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
2598-
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
2599-
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
2600-
lval = zval_get_long_ex(offset, /* is_strict */ true);
2601-
goto str_offset;
2587+
lval = zend_check_string_offset(offset, BP_VAR_R EXECUTE_DATA_CC);
2588+
/* Illegal offset */
2589+
if (UNEXPECTED(EG(exception) != NULL)) {
2590+
return false;
26022591
}
2603-
// TODO Should support resource offsets?
2604-
zend_invalid_offset_type_isset_empty(container, offset);
2605-
return 0;
2592+
goto str_offset;
26062593
}
26072594
} else {
26082595
/* Container is invalid, TODO deprecate this? */
@@ -2633,19 +2620,12 @@ static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *containe
26332620
return 1;
26342621
}
26352622
} else {
2636-
/*if (OP2_TYPE & (IS_CV|IS_VAR)) {*/
2637-
ZVAL_DEREF(offset);
2638-
/*}*/
2639-
// Leading numeric strings can be read...
2640-
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
2641-
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
2642-
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
2643-
lval = zval_get_long_ex(offset, /* is_strict */ true);
2644-
goto str_offset;
2623+
lval = zend_check_string_offset(offset, BP_VAR_R EXECUTE_DATA_CC);
2624+
/* Illegal offset */
2625+
if (UNEXPECTED(EG(exception) != NULL)) {
2626+
return true;
26452627
}
2646-
// TODO Should support resource offsets?
2647-
zend_invalid_offset_type_isset_empty(container, offset);
2648-
return false;
2628+
goto str_offset;
26492629
}
26502630
} else {
26512631
/* Container is invalid, TODO deprecate this? */

tests/strings/offsets_chaining_5.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var_dump($array['expected_array']['0foo']['0bar']);
1717
--EXPECTF--
1818
bool(true)
1919
string(6) "foobar"
20-
Illegal offset type string for container of type string in isset or empty
20+
Cannot access offset of type string on string
2121

2222
Warning: Illegal string offset "0foo" in %s on line %d
2323
string(1) "f"

0 commit comments

Comments
 (0)