Skip to content
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

fix: crashes in ZTS build because of overloaded functions #958

Merged
merged 1 commit into from Mar 28, 2024

Conversation

dunglas
Copy link
Contributor

@dunglas dunglas commented Mar 22, 2024

Closes dunglas/frankenphp#563, closes api-platform/api-platform#2670, closes dunglas/symfony-docker#534, closes https://bugs.xdebug.org/view.php?id=2216, and likely many other random bugs and crashes with ZTS builds.

Rationale:

The function table is (as expected) a different copy for each thread, but each copy points to the same underlying zend_functions, and as we modify them in concurrent threads,, we have a thread safety issue.

In xdebug_base_overloaded_functions_setup, if a thread changes orig->internal_function.handler, then a concurrent thread reads orig->internal_function.handler and stores its value in XG_BASE(orig_error_reporting_func), XG_BASE(orig_error_reporting_func) points to the Xdebug version, instead of to the PHP internal function, and when XG_BASE(orig_error_reporting_func) is called... we get infinite recursion.

This patch moves function overloading in MINIT, as it looks expected: https://www.phpinternalsbook.com/php7/extensions_design/hooks.html#overwriting-an-internal-function

This also allows to simplify the code.

I tested it on Linux, and it fixes the crashes as expected.

@dunglas dunglas marked this pull request as draft March 22, 2024 19:34
@dunglas dunglas marked this pull request as ready for review March 24, 2024 21:12
Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but can you:

@dunglas dunglas force-pushed the fix/overloaded_functions_zts branch from 79a73b4 to 8ff35e5 Compare March 28, 2024 15:13
@dunglas dunglas changed the base branch from master to xdebug_3_3 March 28, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants