Skip to content

Suppress arginfo / zpp mismatch via ZEND_SUPPRESS_ARGINFO_ZPP_MISMATCH #10424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: PHP-8.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PHP NEWS
. Fixed incorrect check condition in ZEND_YIELD. (nielsdos)
. Fixed incorrect check condition in type inference. (nielsdos)
. Fix incorrect check in zend_internal_call_should_throw(). (nielsdos)
. arginfo / zpp validation can now be skipped on debug build with
ZEND_SUPPRESS_ARGINFO_ZPP_MISMATCH=1 (zeriyoshi)

- FFI:
. Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos)
Expand Down
1 change: 1 addition & 0 deletions Zend/tests/arginfo_zpp_mismatch.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function skipFunction($function): bool {
|| $function === 'zend_create_unterminated_string'
|| $function === 'zend_test_array_return'
|| $function === 'zend_leak_bytes'
|| $function === 'zend_test_arginfo_zpp_mismatch'
/* mess with output */
|| (is_string($function) && str_starts_with($function, 'ob_'))
|| $function === 'output_add_rewrite_var'
Expand Down
14 changes: 14 additions & 0 deletions Zend/tests/arginfo_zpp_mismatch_suppress.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test suppressing arginfo / zpp mismatch
--EXTENSIONS--
zend_test
--SKIPIF--
<?php if (!PHP_DEBUG) die('skip debug build only'); ?>
--ENV--
ZEND_SUPPRESS_ARGINFO_ZPP_MISMATCH=1
--FILE--
<?php
zend_test_arginfo_zpp_mismatch(1);
echo 'success';
--EXPECT--
success
14 changes: 14 additions & 0 deletions Zend/tests/arginfo_zpp_mismatch_unsuppress.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test don't suppress arginfo / zpp mismatch
--EXTENSIONS--
zend_test
--SKIPIF--
<?php if (!PHP_DEBUG) die('skip debug build only'); if (extension_loaded('zend opcache')) die('skip sometimes skip arginfo / zpp check on Zend OPcache'); ?>
--ENV--
ZEND_SUPPRESS_ARGINFO_ZPP_MISMATCH=0
--FILE--
<?php
zend_test_arginfo_zpp_mismatch(1);
echo 'success';
--EXPECTF--
Fatal error: Arginfo / zpp mismatch during call of zend_test_arginfo_zpp_mismatch() in %s on line %d
5 changes: 5 additions & 0 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,11 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */
tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
tsrm_set_shutdown_handler(zend_interned_strings_dtor);
#endif

#ifdef ZEND_DEBUG
char *tmp = getenv("ZEND_SUPPRESS_ARGINFO_ZPP_MISMATCH");
EG(suppress_arginfo_zpp_mismatch) = tmp && ZEND_ATOL(tmp);
#endif
}
/* }}} */

Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,10 @@ static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_typ
* trust that arginfo matches what is enforced by zend_parse_parameters. */
ZEND_API bool zend_internal_call_should_throw(zend_function *fbc, zend_execute_data *call)
{
if (EG(suppress_arginfo_zpp_mismatch)) {
return 0;
}

if (fbc->internal_function.handler == ZEND_FN(pass) || (fbc->internal_function.fn_flags & ZEND_ACC_FAKE_CLOSURE)) {
/* Be lenient about the special pass function and about fake closures. */
return 0;
Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ struct _zend_executor_globals {
zend_string *filename_override;
zend_long lineno_override;

#ifdef ZEND_DEBUG
bool suppress_arginfo_zpp_mismatch;
#endif

void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};

Expand Down
13 changes: 13 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,21 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_iterable_legacy, 0, 1, IS_I
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg2, IS_ITERABLE, 1, "null")
ZEND_END_ARG_INFO()

static ZEND_FUNCTION(zend_test_arginfo_zpp_mismatch)
{
zend_long foo;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(foo);
ZEND_PARSE_PARAMETERS_END();
}

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_arginfo_zpp_mismatch, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

static const zend_function_entry ext_function_legacy[] = {
ZEND_FE(zend_iterable_legacy, arginfo_zend_iterable_legacy)
ZEND_FE(zend_test_arginfo_zpp_mismatch, arginfo_zend_test_arginfo_zpp_mismatch)
ZEND_FE_END
};

Expand Down