Closed as not planned
Closed as not planned
Description
Description
Hi,
Currently the zend_hash_real_init_mixed_ex and zend_hash_real_init_packed_ex functions overwrite the hashtable flags which causes the following example to fail:
// allocate a hashtable
HashTable *ht = (HashTable*) emalloc(sizeof(HashTable));
_zend_hash_init(ht, HT_MIN_SIZE, NULL, false);
// then sometime later:
{
GC_ADDREF(ht);
HT_ALLOW_COW_VIOLATION(ht);
zval *value;
ZVAL_LONG(&value, 1);
// HT_ASSERT_RC1(ht) succeeds here because HASH_FLAG_ALLOW_COW_VIOLATION is set.
// However, since the hashtable is uninitialized at this point,
// zend_hash_real_init_packed_ex() is called after the check, which unsets the flag.
zend_hash_next_index_insert(ht, value);
ZVAL_LONG(&value, 2);
// HT_ASSERT_RC1(ht) fails here because HASH_FLAG_ALLOW_COW_VIOLATION
// was cleared in the previous step.
zend_hash_next_index_insert(ht, value);
GC_DELREF(ht);
}
Would you consider a PR that preserves this flag through the initialization process ?
Thanks.
PHP Version
PHP 8.3-dev
Operating System
irrelevant