Skip to content

Commit 6083dc0

Browse files
committed
Fix GH-17991: Assertion failure dom_attr_value_write
Closes GH-17995.
1 parent 6004063 commit 6083dc0

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ PHP NEWS
1212
. Fixed bug GH-17913 (ReflectionFunction::isDeprecated() returns incorrect
1313
results for closures created from magic __call()). (timwolla)
1414

15+
- DOM:
16+
. Fixed bug GH-17991 (Assertion failure dom_attr_value_write). (nielsdos)
17+
1518
- Opcache:
1619
. Fixed bug GH-15834 (Segfault with hook "simple get" cache slot and minimal
1720
JIT). (nielsdos)

ext/dom/php_dom.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,14 @@ static zend_always_inline const dom_prop_handler *dom_get_prop_handler(const dom
372372

373373
if (obj->prop_handler != NULL) {
374374
if (cache_slot && *cache_slot == obj->prop_handler) {
375-
hnd = *(cache_slot + 1);
375+
hnd = cache_slot[1];
376376
}
377377
if (!hnd) {
378378
hnd = zend_hash_find_ptr(obj->prop_handler, name);
379379
if (cache_slot) {
380-
*cache_slot = obj->prop_handler;
381-
*(cache_slot + 1) = (void *) hnd;
380+
cache_slot[0] = obj->prop_handler;
381+
cache_slot[1] = (void *) hnd;
382+
cache_slot[2] = NULL;
382383
}
383384
}
384385
}

ext/dom/tests/gh17991.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-17991 (Assertion failure dom_attr_value_write)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$attr = new DOMAttr("r", "iL");
8+
class Box {
9+
public ?Test $value;
10+
}
11+
class Test {
12+
}
13+
function test($box) {
14+
var_dump($box->value = new Test);
15+
}
16+
$box = new Box();
17+
test($box);
18+
test($attr);
19+
?>
20+
--EXPECTF--
21+
object(Test)#%d (0) {
22+
}
23+
24+
Fatal error: Uncaught TypeError: Cannot assign Test to property DOMAttr::$value of type string in %s:%d
25+
Stack trace:
26+
#0 %s(%d): test(Object(DOMAttr))
27+
#1 {main}
28+
thrown in %s on line %d

0 commit comments

Comments
 (0)