Skip to content

Commit d03025b

Browse files
nielsdosGirgias
authored andcommitted
Fix GH-10251: Assertion `(flag & (1<<3)) == 0' failed.
zend_get_property_guard previously assumed that at least "str" has a pre-computed hash. This is not always the case, for example when a string is created by bitwise operations, its hash is not set. Instead of forcing a computation of the hashes, drop the hash comparison. Closes GH-10254 Co-authored-by: Changochen <changochen1@gmail.com> Signed-off-by: George Peter Banyard <girgias@php.net>
1 parent 8ff2b6a commit d03025b

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHP NEWS
88
- Core:
99
. Fixed bug GH-10072 (PHP crashes when execute_ex is overridden and a __call
1010
trampoline is used from internal code). (Derick)
11+
. Fix GH-10251 (Assertion `(flag & (1<<3)) == 0' failed). (nielsdos)
1112

1213
- Date:
1314
. Fixed bug GH-9891 (DateTime modify with unixtimestamp (@) must work like

Zend/tests/gh10251.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-10251 (Assertion `(flag & (1<<3)) == 0' failed.)
3+
--FILE--
4+
<?php
5+
class A
6+
{
7+
function __set($o, $l)
8+
{
9+
$this->$p = $v;
10+
}
11+
}
12+
$a = new A();
13+
$pp = "";
14+
$op = $pp & "";
15+
// Bitwise operators on strings don't compute the hash.
16+
// The code below previously assumed a hash was actually computed, leading to a crash.
17+
$a->$op = 0;
18+
echo "Done\n";
19+
?>
20+
--EXPECTF--
21+
Warning: Undefined variable $v in %s on line %d
22+
23+
Warning: Undefined variable $p in %s on line %d
24+
Done

Zend/zend_object_handlers.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,8 @@ ZEND_API uint32_t *zend_get_property_guard(zend_object *zobj, zend_string *membe
535535
if (EXPECTED(Z_TYPE_P(zv) == IS_STRING)) {
536536
zend_string *str = Z_STR_P(zv);
537537
if (EXPECTED(str == member) ||
538-
/* "str" always has a pre-calculated hash value here */
539-
(EXPECTED(ZSTR_H(str) == zend_string_hash_val(member)) &&
540-
EXPECTED(zend_string_equal_content(str, member)))) {
538+
/* str and member don't necessarily have a pre-calculated hash value here */
539+
EXPECTED(zend_string_equal_content(str, member))) {
541540
return &Z_PROPERTY_GUARD_P(zv);
542541
} else if (EXPECTED(Z_PROPERTY_GUARD_P(zv) == 0)) {
543542
zval_ptr_dtor_str(zv);

0 commit comments

Comments
 (0)