Skip to content

HASH_FLAG_ALLOW_COW_VIOLATION is not preserved by zend_hash_real_init_(mixed|packed)_ex() #12986

Closed as not planned
@ju1ius

Description

@ju1ius

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions