Skip to content

Commit a6ce4c5

Browse files
committed
preserves HASH_FLAG_ALLOW_COW_VIOLATION in zend_hash_real_init_ex
Closes #12986
1 parent 19357ab commit a6ce4c5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Zend/zend_hash.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static zend_always_inline uint32_t zend_hash_check_size(uint32_t nSize)
149149
static zend_always_inline void zend_hash_real_init_packed_ex(HashTable *ht)
150150
{
151151
void *data;
152+
uint8_t prev_flags = HT_FLAGS(ht) & HASH_FLAG_ALLOW_COW_VIOLATION;
152153

153154
if (UNEXPECTED(GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)) {
154155
data = pemalloc(HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK), 1);
@@ -160,14 +161,15 @@ static zend_always_inline void zend_hash_real_init_packed_ex(HashTable *ht)
160161
}
161162
HT_SET_DATA_ADDR(ht, data);
162163
/* Don't overwrite iterator count. */
163-
ht->u.v.flags = HASH_FLAG_PACKED | HASH_FLAG_STATIC_KEYS;
164+
ht->u.v.flags = prev_flags | HASH_FLAG_PACKED | HASH_FLAG_STATIC_KEYS;
164165
HT_HASH_RESET_PACKED(ht);
165166
}
166167

167168
static zend_always_inline void zend_hash_real_init_mixed_ex(HashTable *ht)
168169
{
169170
void *data;
170171
uint32_t nSize = ht->nTableSize;
172+
uint8_t prev_flags = HT_FLAGS(ht) & HASH_FLAG_ALLOW_COW_VIOLATION;
171173

172174
ZEND_ASSERT(HT_SIZE_TO_MASK(nSize));
173175

@@ -178,7 +180,7 @@ static zend_always_inline void zend_hash_real_init_mixed_ex(HashTable *ht)
178180
ht->nTableMask = HT_SIZE_TO_MASK(HT_MIN_SIZE);
179181
HT_SET_DATA_ADDR(ht, data);
180182
/* Don't overwrite iterator count. */
181-
ht->u.v.flags = HASH_FLAG_STATIC_KEYS;
183+
ht->u.v.flags = prev_flags | HASH_FLAG_STATIC_KEYS;
182184
#if defined(__AVX2__)
183185
do {
184186
__m256i ymm0 = _mm256_setzero_si256();
@@ -227,7 +229,7 @@ static zend_always_inline void zend_hash_real_init_mixed_ex(HashTable *ht)
227229
}
228230
ht->nTableMask = HT_SIZE_TO_MASK(nSize);
229231
HT_SET_DATA_ADDR(ht, data);
230-
HT_FLAGS(ht) = HASH_FLAG_STATIC_KEYS;
232+
HT_FLAGS(ht) = prev_flags | HASH_FLAG_STATIC_KEYS;
231233
HT_HASH_RESET(ht);
232234
}
233235

0 commit comments

Comments
 (0)