Skip to content

Commit 1f809a5

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-20043: array_unique assertion failure with RC1 array causing an exception on sort
2 parents 90e2708 + f2f84e3 commit 1f809a5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ext/standard/array.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,6 +5044,11 @@ PHP_FUNCTION(array_unique)
50445044
ZVAL_UNDEF(&arTmp[i].b.val);
50455045
zend_sort((void *) arTmp, i, sizeof(struct bucketindex),
50465046
(compare_func_t) cmp, (swap_func_t) array_bucketindex_swap);
5047+
5048+
if (UNEXPECTED(EG(exception))) {
5049+
goto out;
5050+
}
5051+
50475052
/* go through the sorted array and delete duplicates from the copy */
50485053
lastkept = arTmp;
50495054
for (cmpdata = arTmp + 1; Z_TYPE(cmpdata->b.val) != IS_UNDEF; cmpdata++) {
@@ -5063,6 +5068,8 @@ PHP_FUNCTION(array_unique)
50635068
}
50645069
}
50655070
}
5071+
5072+
out:
50665073
pefree(arTmp, GC_FLAGS(Z_ARRVAL_P(array)) & IS_ARRAY_PERSISTENT);
50675074

50685075
if (in_place) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-20043 (array_unique assertion failure with RC1 array causing an exception on sort)
3+
--FILE--
4+
<?php
5+
try {
6+
array_unique([new stdClass, new stdClass], SORT_STRING | SORT_FLAG_CASE);
7+
} catch (Error $e) {
8+
echo $e->getMessage();
9+
}
10+
?>
11+
--EXPECT--
12+
Object of class stdClass could not be converted to string

0 commit comments

Comments
 (0)