Skip to content

Commit 1fe8a1d

Browse files
committed
Merge branch 'PHP-7.0'
* PHP-7.0: Fixed possible crash on Zend/tests/bug71154.phpt
2 parents b851512 + 0402f05 commit 1fe8a1d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Zend/zend_hash.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,30 @@ ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos(uint32_t idx, HashTab
386386
return iter->pos;
387387
}
388388

389+
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos_ex(uint32_t idx, zval *array)
390+
{
391+
HashTable *ht = Z_ARRVAL_P(array);
392+
HashTableIterator *iter = EG(ht_iterators) + idx;
393+
394+
ZEND_ASSERT(idx != (uint32_t)-1);
395+
if (iter->pos == HT_INVALID_IDX) {
396+
return HT_INVALID_IDX;
397+
} else if (UNEXPECTED(iter->ht != ht)) {
398+
if (EXPECTED(iter->ht) && EXPECTED(iter->ht != HT_POISONED_PTR)
399+
&& EXPECTED(iter->ht->u.v.nIteratorsCount != 255)) {
400+
iter->ht->u.v.nIteratorsCount--;
401+
}
402+
SEPARATE_ARRAY(array);
403+
ht = Z_ARRVAL_P(array);
404+
if (EXPECTED(ht->u.v.nIteratorsCount != 255)) {
405+
ht->u.v.nIteratorsCount++;
406+
}
407+
iter->ht = ht;
408+
iter->pos = ht->nInternalPointer;
409+
}
410+
return iter->pos;
411+
}
412+
389413
ZEND_API void ZEND_FASTCALL zend_hash_iterator_del(uint32_t idx)
390414
{
391415
HashTableIterator *iter = EG(ht_iterators) + idx;

Zend/zend_hash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ ZEND_API int ZEND_FASTCALL _zend_handle_numeric_str_ex(const char *key, size_t l
225225

226226
ZEND_API uint32_t ZEND_FASTCALL zend_hash_iterator_add(HashTable *ht, HashPosition pos);
227227
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos(uint32_t idx, HashTable *ht);
228+
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos_ex(uint32_t idx, zval *array);
228229
ZEND_API void ZEND_FASTCALL zend_hash_iterator_del(uint32_t idx);
229230
ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterators_lower_pos(HashTable *ht, HashPosition start);
230231
ZEND_API void ZEND_FASTCALL _zend_hash_iterators_update(HashTable *ht, HashPosition from, HashPosition to);

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6320,8 +6320,8 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
63206320

63216321
ZVAL_DEREF(array);
63226322
if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) {
6323+
pos = zend_hash_iterator_pos_ex(Z_FE_ITER_P(EX_VAR(opline->op1.var)), array);
63236324
fe_ht = Z_ARRVAL_P(array);
6324-
pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht);
63256325
p = fe_ht->arData + pos;
63266326
while (1) {
63276327
if (UNEXPECTED(pos >= fe_ht->nNumUsed)) {

Zend/zend_vm_execute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15946,8 +15946,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER(Z
1594615946

1594715947
ZVAL_DEREF(array);
1594815948
if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) {
15949+
pos = zend_hash_iterator_pos_ex(Z_FE_ITER_P(EX_VAR(opline->op1.var)), array);
1594915950
fe_ht = Z_ARRVAL_P(array);
15950-
pos = zend_hash_iterator_pos(Z_FE_ITER_P(EX_VAR(opline->op1.var)), fe_ht);
1595115951
p = fe_ht->arData + pos;
1595215952
while (1) {
1595315953
if (UNEXPECTED(pos >= fe_ht->nNumUsed)) {

0 commit comments

Comments
 (0)