Skip to content

Commit 603b9c4

Browse files
committed
Add arg type assertions to DO_ICALL
Now that DO_ICALL is also used for functions with type hints, we should include the arginfo sanity check assertions in there as well.
1 parent 33e10fe commit 603b9c4

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Zend/zend_vm_def.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4010,13 +4010,23 @@ ZEND_VM_HOT_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL))
40104010
call->prev_execute_data = execute_data;
40114011
EG(current_execute_data) = call;
40124012

4013+
#if ZEND_DEBUG
4014+
/* Type checks for internal functions are usually only performed by zpp.
4015+
* In debug mode we additionally run arginfo checks to detect cases where
4016+
* arginfo and zpp went out of sync. */
4017+
zend_bool wrong_arg_types =
4018+
(fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) &&
4019+
!zend_verify_internal_arg_types(fbc, call);
4020+
#endif
4021+
40134022
ret = RETURN_VALUE_USED(opline) ? EX_VAR(opline->result.var) : &retval;
40144023
ZVAL_NULL(ret);
40154024

40164025
fbc->internal_function.handler(call, ret);
40174026

40184027
#if ZEND_DEBUG
40194028
if (!EG(exception) && call->func) {
4029+
ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?");
40204030
ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) ||
40214031
zend_verify_internal_return_type(call->func, ret));
40224032
ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)
@@ -4101,7 +4111,6 @@ ZEND_VM_HOT_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL))
41014111
call->prev_execute_data = execute_data;
41024112
EG(current_execute_data) = call;
41034113

4104-
41054114
#if ZEND_DEBUG
41064115
/* Type checks for internal functions are usually only performed by zpp.
41074116
* In debug mode we additionally run arginfo checks to detect cases where

Zend/zend_vm_execute.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,13 +1266,23 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETV
12661266
call->prev_execute_data = execute_data;
12671267
EG(current_execute_data) = call;
12681268

1269+
#if ZEND_DEBUG
1270+
/* Type checks for internal functions are usually only performed by zpp.
1271+
* In debug mode we additionally run arginfo checks to detect cases where
1272+
* arginfo and zpp went out of sync. */
1273+
zend_bool wrong_arg_types =
1274+
(fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) &&
1275+
!zend_verify_internal_arg_types(fbc, call);
1276+
#endif
1277+
12691278
ret = 0 ? EX_VAR(opline->result.var) : &retval;
12701279
ZVAL_NULL(ret);
12711280

12721281
fbc->internal_function.handler(call, ret);
12731282

12741283
#if ZEND_DEBUG
12751284
if (!EG(exception) && call->func) {
1285+
ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?");
12761286
ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) ||
12771287
zend_verify_internal_return_type(call->func, ret));
12781288
ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)
@@ -1311,13 +1321,23 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETV
13111321
call->prev_execute_data = execute_data;
13121322
EG(current_execute_data) = call;
13131323

1324+
#if ZEND_DEBUG
1325+
/* Type checks for internal functions are usually only performed by zpp.
1326+
* In debug mode we additionally run arginfo checks to detect cases where
1327+
* arginfo and zpp went out of sync. */
1328+
zend_bool wrong_arg_types =
1329+
(fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) &&
1330+
!zend_verify_internal_arg_types(fbc, call);
1331+
#endif
1332+
13141333
ret = 1 ? EX_VAR(opline->result.var) : &retval;
13151334
ZVAL_NULL(ret);
13161335

13171336
fbc->internal_function.handler(call, ret);
13181337

13191338
#if ZEND_DEBUG
13201339
if (!EG(exception) && call->func) {
1340+
ZEND_ASSERT(!wrong_arg_types && "Arginfo / zpp type mismatch?");
13211341
ZEND_ASSERT(!(call->func->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) ||
13221342
zend_verify_internal_return_type(call->func, ret));
13231343
ZEND_ASSERT((call->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)
@@ -1425,7 +1445,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
14251445
call->prev_execute_data = execute_data;
14261446
EG(current_execute_data) = call;
14271447

1428-
14291448
#if ZEND_DEBUG
14301449
/* Type checks for internal functions are usually only performed by zpp.
14311450
* In debug mode we additionally run arginfo checks to detect cases where
@@ -1504,7 +1523,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_S
15041523
call->prev_execute_data = execute_data;
15051524
EG(current_execute_data) = call;
15061525

1507-
15081526
#if ZEND_DEBUG
15091527
/* Type checks for internal functions are usually only performed by zpp.
15101528
* In debug mode we additionally run arginfo checks to detect cases where

0 commit comments

Comments
 (0)