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 incorrect zval type_flags in preg_replace_callback_array() for immutable arrays #10970

Closed
wants to merge 1 commit into from

Conversation

iluuu1994
Copy link
Member

The ZVAL_ARR macro always set the zval type_info to IS_ARRAY_EX, even if the hash table is immutable. Since in preg_replace_callback_array() we can return the passed array directly, and that passed array can be immutable, we need to reset the type_flags to keep the VM from performing ref-counting on the array.

Fixes GH-10968

We could also introduce a new macro for this but I couldn't find another place that potentially returns an immutable array.

…mutable arrays

The ZVAL_ARR macro always set the zval type_info to IS_ARRAY_EX, even if the
hash table is immutable. Since in preg_replace_callback_array() we can return
the passed array directly, and that passed array can be immutable, we need to
reset the type_flags to keep the VM from performing ref-counting on the array.

Fixes phpGH-10968
@@ -2479,7 +2479,11 @@ PHP_FUNCTION(preg_replace_callback_array)
}

if (subject_ht) {
RETURN_ARR(subject_ht);
RETVAL_ARR(subject_ht);
if (GC_FLAGS(subject_ht) & GC_IMMUTABLE) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (GC_FLAGS(subject_ht) & GC_IMMUTABLE) {
if (GC_FLAGS(subject_ht) & IS_ARRAY_IMMUTABLE) {

Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I forgot we have an alias. Thanks!

@iluuu1994 iluuu1994 closed this in 66ce205 Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants