Skip to content

Commit d37c328

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.
1 parent f11228c commit d37c328

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ext/standard/array.c

Lines changed: 2 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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)