Skip to content

Commit 1da41af

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix incorrect HASH_FLAG_HAS_EMPTY_IND flag on userland array
2 parents 1c323f1 + f045716 commit 1da41af

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
@@ -10,6 +10,8 @@ PHP NEWS
1010
exception are triggered). (nielsdos)
1111
. Fixed bug GH-19653 (Closure named argument unpacking between temporary
1212
closures can cause a crash). (nielsdos, Arnaud, Bob)
13+
. Fixed bug GH-19839 (Incorrect HASH_FLAG_HAS_EMPTY_IND flag on userland
14+
array). (ilutov)
1315

1416
- Curl:
1517
. 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
@@ -2465,6 +2465,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
24652465
target->nTableSize = HT_MIN_SIZE;
24662466
HT_SET_DATA_ADDR(target, &uninitialized_bucket);
24672467
} else if (GC_FLAGS(source) & IS_ARRAY_IMMUTABLE) {
2468+
ZEND_ASSERT(!(HT_FLAGS(source) & HASH_FLAG_HAS_EMPTY_IND));
24682469
HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK;
24692470
target->nTableMask = source->nTableMask;
24702471
target->nNumUsed = source->nNumUsed;
@@ -2481,6 +2482,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
24812482
memcpy(HT_GET_DATA_ADDR(target), HT_GET_DATA_ADDR(source), HT_USED_SIZE(source));
24822483
}
24832484
} else if (HT_IS_PACKED(source)) {
2485+
ZEND_ASSERT(!(HT_FLAGS(source) & HASH_FLAG_HAS_EMPTY_IND));
24842486
HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK;
24852487
target->nTableMask = HT_MIN_MASK;
24862488
target->nNumUsed = source->nNumUsed;
@@ -2500,7 +2502,8 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source)
25002502
zend_array_dup_packed_elements(source, target, 1);
25012503
}
25022504
} else {
2503-
HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK;
2505+
/* Indirects are removed during duplication, remove HASH_FLAG_HAS_EMPTY_IND accordingly. */
2506+
HT_FLAGS(target) = HT_FLAGS(source) & (HASH_FLAG_MASK & ~HASH_FLAG_HAS_EMPTY_IND);
25042507
target->nTableMask = source->nTableMask;
25052508
target->nNextFreeElement = source->nNextFreeElement;
25062509
target->nInternalPointer =

0 commit comments

Comments
 (0)