Skip to content

Commit 0505586

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix incorrect HASH_FLAG_HAS_EMPTY_IND flag on userland array
2 parents 28fc06b + 1da41af commit 0505586

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
checks). (timwolla)
88
. The __sleep() and __wakeup() magic methods have been deprecated. (Girgias)
99
. Fixed hard_timeout with --enable-zend-max-execution-timers. (Appla)
10+
. Fixed bug GH-19839 (Incorrect HASH_FLAG_HAS_EMPTY_IND flag on userland
11+
array). (ilutov)
1012

1113
- Curl:
1214
. Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead

Zend/tests/gh19839.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-19839: Incorrect HASH_FLAG_HAS_EMPTY_IND flag on userland array
3+
--FILE--
4+
<?php
5+
6+
const X = 'x';
7+
8+
$x = null;
9+
unset(${X});
10+
11+
$a = $GLOBALS;
12+
sort($a);
13+
serialize($a);
14+
15+
?>
16+
===DONE===
17+
--EXPECT--
18+
===DONE===

Zend/zend_hash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(const HashTable *source)
24642464
target->nTableSize = HT_MIN_SIZE;
24652465
HT_SET_DATA_ADDR(target, &uninitialized_bucket);
24662466
} else if (GC_FLAGS(source) & IS_ARRAY_IMMUTABLE) {
2467+
ZEND_ASSERT(!(HT_FLAGS(source) & HASH_FLAG_HAS_EMPTY_IND));
24672468
HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK;
24682469
target->nTableMask = source->nTableMask;
24692470
target->nNumUsed = source->nNumUsed;
@@ -2480,6 +2481,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(const HashTable *source)
24802481
memcpy(HT_GET_DATA_ADDR(target), HT_GET_DATA_ADDR(source), HT_USED_SIZE(source));
24812482
}
24822483
} else if (HT_IS_PACKED(source)) {
2484+
ZEND_ASSERT(!(HT_FLAGS(source) & HASH_FLAG_HAS_EMPTY_IND));
24832485
HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK;
24842486
target->nTableMask = HT_MIN_MASK;
24852487
target->nNumUsed = source->nNumUsed;
@@ -2499,7 +2501,8 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(const HashTable *source)
24992501
zend_array_dup_packed_elements(source, target, 1);
25002502
}
25012503
} else {
2502-
HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK;
2504+
/* Indirects are removed during duplication, remove HASH_FLAG_HAS_EMPTY_IND accordingly. */
2505+
HT_FLAGS(target) = HT_FLAGS(source) & (HASH_FLAG_MASK & ~HASH_FLAG_HAS_EMPTY_IND);
25032506
target->nTableMask = source->nTableMask;
25042507
target->nNextFreeElement = source->nNextFreeElement;
25052508
target->nInternalPointer =

0 commit comments

Comments
 (0)