com php-src: Forbid exchangeArray() during sorting: ext/spl/spl_array.c ext/spl/tests/ArrayObject_exchange _array_during_sorting.phpt
| From: | Nikita Popov | Date: | Wed, 24 Feb 2016 21:34:50 +0000 |
| Subject: | com php-src: Forbid exchangeArray() during sorting: ext/spl/spl_array.c ext/spl/tests/ArrayObject_exchange _array_during_sorting.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-91162@lists.php.net to get a copy of this message | ||
Commit: 079f2f7eb31659569cd2663e2c5b4c9f9eaa32d7
Author: Nikita Popov <nikic@php.net> Wed, 24 Feb 2016 18:27:56 +0100
Parents: b65755458538e1c5396144356bb99c97db2efee9
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=079f2f7eb31659569cd2663e2c5b4c9f9eaa32d7
Log:
Forbid exchangeArray() during sorting
Previously this would leak.
Changed paths:
M ext/spl/spl_array.c
A ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt
Diff:
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 0740c06..2de985b 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -1267,6 +1267,11 @@ SPL_METHOD(Array, exchangeArray)
return;
}
+ if (intern->nApplyCount > 0) {
+ zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+ return;
+ }
+
RETVAL_ARR(zend_array_dup(spl_array_get_hash_table(intern)));
spl_array_set_array(object, intern, array, 0L, 1);
}
diff --git a/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt
b/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt
new file mode 100644
index 0000000..225d42c
--- /dev/null
+++ b/ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Can't use exchangeArray() while ArrayObject is being sorted
+--FILE--
+<?php
+
+$ao = new ArrayObject([1, 2, 3]);
+$i = 0;
+$ao->uasort(function($a, $b) use ($ao, &$i) {
+ if ($i++ == 0) {
+ $ao->exchangeArray([4, 5, 6]);
+ var_dump($ao);
+ }
+ return $a <=> $b;
+});
+
+?>
+--EXPECTF--
+Warning: Modification of ArrayObject during sorting is prohibited in %s on line %d
+object(ArrayObject)#1 (1) {
+ ["storage":"ArrayObject":private]=>
+ array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ }
+}