-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix array going away during sorting #16654
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
Conversation
Zend/zend_hash.c
Outdated
/* The array _should_ be added to the gc buffer. However, this causes an | ||
* issue for non-user hashtables that use zend_hash_destroy(), which does | ||
* not remove the destroyed array from the gc buffer, assuming it was | ||
* never added. */ | ||
// gc_check_possible_root((zend_refcounted *)ht); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may try to move this locking code into asort()
and others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll have to (re)move HT_ASSERT_RC1(ht);
from zend_hash_sort_ex()
, but I think this should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving HT_ASSERT_RC1(ht);
is bad :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstogov We could introduce another variant of zend_hash_sort_ex()
that omits it, which can be used explicitly for cases like this. We could also add HASH_FLAG_ALLOW_COW_VIOLATION
, but since user-code may run during sorting this is likely worse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, zend_array_sort()
with the new protection should work.
Since this now adds new API, it's likely better to just fix in |
@iluuu1994 Adding new API has never been a blocker. (Changing API, yes.) And it does fix a real bug. |
Actually, it's better not to add new API calls. |
Right. What I was referencing was this scenario: Extensions start using the new API, the user updates to the new extension without updating PHP, after which dynamic loading of the extension would fail. This can be prevented by the approach Dmitry described. Another upside is that the API may actually still be changed until |
It's ok to add a new API but probably a bit nicer for extension authors not to add it in if it's not necessary. So agree that keeping it internal in general might be better even though it's already in exported headers and it's just a hint for most users (all except Windows where |
FWIW, Edit: And just as I'm writing this, I realized we shouldn't use this function for ext/intl/collator/collator_sort.c yet. 🙂 |
Fixes GH-16648