Skip to content

Commit ad04345

Browse files
committed
Fix GH-9244: Segfault with array_multisort + array_shift
After restructuring non-packed arrays, we either need to pack them if possible, or to rehash them. Closes GH-9247.
1 parent a6f489b commit ad04345

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020

2121
- Standard:
2222
. Fixed bug #65489 (glob() basedir check is inconsistent). (Jakub Zelenka)
23+
. Fixed GH-9244 (Segfault with array_multisort + array_shift). (cmb)
2324

2425
04 Aug 2022, PHP 8.2.0beta2
2526

ext/standard/array.c

+2
Original file line numberDiff line numberDiff line change
@@ -5791,6 +5791,8 @@ PHP_FUNCTION(array_multisort)
57915791
}
57925792
if (repack) {
57935793
zend_hash_to_packed(hash);
5794+
} else {
5795+
zend_hash_rehash(hash);
57945796
}
57955797
}
57965798
}

ext/standard/tests/array/gh9244.phpt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug GH-9244 (Segfault with array_multisort + array_shift)
3+
--FILE--
4+
<?php
5+
$items = ['foo' => 1, 'bar' => 2];
6+
$order = [4, 3];
7+
array_multisort($order, $items);
8+
var_dump(array_shift($items));
9+
?>
10+
--EXPECT--
11+
int(2)

0 commit comments

Comments
 (0)