Skip to content

Commit f2f84e3

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phpGH-20043: array_unique assertion failure with RC1 array causing an exception on sort
2 parents b79817b + 4fed57e commit f2f84e3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ PHP NEWS
6060
. Fixed bug GH-19701 (Serialize/deserialize loses some data). (nielsdos)
6161
. Fixed bug GH-19801 (leaks in var_dump() and debug_zval_dump()).
6262
(alexandre-daubois)
63+
. Fixed bug GH-20043 (array_unique assertion failure with RC1 array
64+
causing an exception on sort). (nielsdos)
6365

6466
- Streams:
6567
. Fixed bug GH-19248 (Use strerror_r instead of strerror in main).

ext/standard/array.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5027,6 +5027,11 @@ PHP_FUNCTION(array_unique)
50275027
ZVAL_UNDEF(&arTmp[i].b.val);
50285028
zend_sort((void *) arTmp, i, sizeof(struct bucketindex),
50295029
(compare_func_t) cmp, (swap_func_t) array_bucketindex_swap);
5030+
5031+
if (UNEXPECTED(EG(exception))) {
5032+
goto out;
5033+
}
5034+
50305035
/* go through the sorted array and delete duplicates from the copy */
50315036
lastkept = arTmp;
50325037
for (cmpdata = arTmp + 1; Z_TYPE(cmpdata->b.val) != IS_UNDEF; cmpdata++) {
@@ -5046,6 +5051,8 @@ PHP_FUNCTION(array_unique)
50465051
}
50475052
}
50485053
}
5054+
5055+
out:
50495056
pefree(arTmp, GC_FLAGS(Z_ARRVAL_P(array)) & IS_ARRAY_PERSISTENT);
50505057

50515058
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)