Skip to content

Commit 51c38a0

Browse files
laruencesmalyshev
authored andcommitted
Fixed bug #67539 (ArrayIterator use-after-free due to object change during sorting)
1 parent 61e0f85 commit 51c38a0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ext/spl/spl_array.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,7 @@ SPL_METHOD(Array, unserialize)
17451745
const unsigned char *p, *s;
17461746
php_unserialize_data_t var_hash;
17471747
zval *pmembers, *pflags = NULL;
1748+
HashTable *aht;
17481749
long flags;
17491750

17501751
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) == FAILURE) {
@@ -1756,6 +1757,12 @@ SPL_METHOD(Array, unserialize)
17561757
return;
17571758
}
17581759

1760+
aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
1761+
if (aht->nApplyCount > 0) {
1762+
zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
1763+
return;
1764+
}
1765+
17591766
/* storage */
17601767
s = p = (const unsigned char*)buf;
17611768
PHP_VAR_UNSERIALIZE_INIT(var_hash);

ext/spl/tests/bug67539.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #67539 (ArrayIterator use-after-free due to object change during sorting)
3+
--FILE--
4+
<?php
5+
6+
$it = new ArrayIterator(array_fill(0,2,'X'), 1 );
7+
8+
function badsort($a, $b) {
9+
$GLOBALS['it']->unserialize($GLOBALS['it']->serialize());
10+
return TRUE;
11+
}
12+
13+
$it->uksort('badsort');
14+
--EXPECTF--
15+
Warning: Modification of ArrayObject during sorting is prohibited in %sbug67539.php on line %d

0 commit comments

Comments
 (0)