-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-20262: array_unique() SORT_REGULAR fails to deduplicate with mixed strings #20273
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
Closed
+662
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4102fe6 to
f60a45f
Compare
…h mixed strings array_unique() with SORT_REGULAR was failing to remove duplicate numeric strings when mixed with alphanumeric strings due to non-transitive comparison issues in the sort-based algorithm. Implemented hash-bucketing optimization for SORT_REGULAR that preserves full type coercion semantics while improving performance from O(n²) to O(n). Closes phpGH-20262
f60a45f to
c4fc6a9
Compare
devnexen
reviewed
Oct 24, 2025
ndossche
reviewed
Oct 24, 2025
- Eliminate Hash-DoS and integer overflow vulnerabilities - Add exception handling to prevent memory leaks - Implement type-specific optimizations (hash/sort/bucket) - Dynamic bucket sizing for memory efficiency - Fix resource handling
This was referenced Oct 24, 2025
Use ZVAL_DEREF macro to dereference values before comparing in the array_unique function. Also add a new test case to verify the behavior.
devnexen
reviewed
Oct 25, 2025
|
Another variation of the example bug, but using objects: My PR does not make an attempt to resolve this issue with complex types. |
|
Closing in favor of #20305 which provides a complete solution that fixes transitivity for all mixed types (scalars, nested arrays, and objects). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Bug
array_unique()withSORT_REGULARwas failing to remove duplicate numeric strings when mixed with alphanumeric strings:Root Cause
Non-transitive comparisons in
SORT_REGULAR(where'5' == 5and5 != '5abc'but'5' < '5abc') broke the sort-based algorithm's assumption that sorting would group duplicates adjacently.Solution
Implemented type-optimized hybrid approach for
SORT_REGULAR:Three-tier algorithm selection:
Performance
Improved performance across all data types compared to PHP 8.4.13 while fixing correctness issues.
Backward Compatibility
Tests Added
gh20262.phpt- Minimal regression test for the bugarray_unique_variation_sort_regular.phpt- Comprehensive SORT_REGULAR behavior coverage (16 scenarios)