Skip to content

Commit f965e20

Browse files
committed
Promote ArrayObject modification during sorting to Error exception
1 parent 99c5e08 commit f965e20

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

ext/spl/spl_array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *
287287
}
288288

289289
if ((type == BP_VAR_W || type == BP_VAR_RW) && intern->nApplyCount > 0) {
290-
zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
290+
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
291291
return &EG(error_zval);
292292
}
293293

@@ -456,7 +456,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec
456456
}
457457

458458
if (intern->nApplyCount > 0) {
459-
zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
459+
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
460460
return;
461461
}
462462

@@ -524,7 +524,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec
524524
}
525525

526526
if (intern->nApplyCount > 0) {
527-
zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
527+
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
528528
return;
529529
}
530530

@@ -1285,7 +1285,7 @@ PHP_METHOD(ArrayObject, exchangeArray)
12851285
}
12861286

12871287
if (intern->nApplyCount > 0) {
1288-
zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
1288+
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
12891289
return;
12901290
}
12911291

@@ -1675,7 +1675,7 @@ PHP_METHOD(ArrayObject, unserialize)
16751675
}
16761676

16771677
if (intern->nApplyCount > 0) {
1678-
zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
1678+
zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
16791679
return;
16801680
}
16811681

ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ $ao = new ArrayObject([1, 2, 3]);
77
$i = 0;
88
$ao->uasort(function($a, $b) use ($ao, &$i) {
99
if ($i++ == 0) {
10-
$ao->exchangeArray([4, 5, 6]);
10+
try {
11+
$ao->exchangeArray([4, 5, 6]);
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
1115
var_dump($ao);
1216
}
1317
return $a <=> $b;
1418
});
1519

1620
?>
17-
--EXPECTF--
18-
Warning: Modification of ArrayObject during sorting is prohibited in %s on line %d
21+
--EXPECT--
22+
Modification of ArrayObject during sorting is prohibited
1923
object(ArrayObject)#1 (1) {
2024
["storage":"ArrayObject":private]=>
2125
array(3) {

ext/spl/tests/bug67539.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ Bug #67539 (ArrayIterator use-after-free due to object change during sorting)
66
$it = new ArrayIterator(array_fill(0,2,'X'), 1 );
77

88
function badsort($a, $b) {
9+
try {
910
$GLOBALS['it']->unserialize($GLOBALS['it']->serialize());
10-
return 0;
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
return 0;
1115
}
1216

1317
$it->uksort('badsort');
1418
?>
15-
--EXPECTF--
16-
Warning: Modification of ArrayObject during sorting is prohibited in %sbug67539.php on line %d
19+
--EXPECT--
20+
Modification of ArrayObject during sorting is prohibited

0 commit comments

Comments
 (0)