Skip to content

Commit 82c504f

Browse files
authored
Fix GH-15670: Polymorphic cache slot issue in DOM (#15676)
A cache slot can be hit with different DOM object types, so we should check if we're still handling the same type.
1 parent 73b7993 commit 82c504f

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

ext/dom/php_dom.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,14 @@ static zend_always_inline const dom_prop_handler *dom_get_prop_handler(const dom
370370
const dom_prop_handler *hnd = NULL;
371371

372372
if (obj->prop_handler != NULL) {
373-
if (cache_slot) {
374-
hnd = *cache_slot;
373+
if (cache_slot && *cache_slot == obj->prop_handler) {
374+
hnd = *(cache_slot + 1);
375375
}
376376
if (!hnd) {
377377
hnd = zend_hash_find_ptr(obj->prop_handler, name);
378378
if (cache_slot) {
379-
*cache_slot = (void *) hnd;
379+
*cache_slot = obj->prop_handler;
380+
*(cache_slot + 1) = (void *) hnd;
380381
}
381382
}
382383
}
@@ -419,12 +420,13 @@ zval *dom_write_property(zend_object *object, zend_string *name, zval *value, vo
419420

420421
zend_property_info *prop = NULL;
421422
if (cache_slot) {
422-
prop = *(cache_slot + 1);
423+
ZEND_ASSERT(*cache_slot == obj->prop_handler);
424+
prop = *(cache_slot + 2);
423425
}
424426
if (!prop) {
425427
prop = zend_get_property_info(object->ce, name, /* silent */ true);
426428
if (cache_slot) {
427-
*(cache_slot + 1) = prop;
429+
*(cache_slot + 2) = prop;
428430
}
429431
}
430432

ext/dom/tests/gh15670.phpt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-15670 (Polymorphic cache slot issue in DOM)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument();
8+
$doc->loadHTML('<p id=x>foo</p>');
9+
$dom = DOM\XMLDocument::createFromString('<root/>');
10+
$child = $dom->documentElement->appendChild($dom->createElementNS('urn:a', 'child'));
11+
function test($child, $html) {
12+
try {
13+
$child->innerHTML = $html;
14+
} catch (DOMException $e) {
15+
}
16+
}
17+
test($child, '--></root><!--');
18+
test($doc, '<');
19+
echo $doc->saveXML(), "\n";
20+
echo $dom->saveXML(), "\n";
21+
?>
22+
--EXPECTF--
23+
Deprecated: Creation of dynamic property DOMDocument::$innerHTML is deprecated in %s on line %d
24+
<?xml version="1.0" standalone="yes"?>
25+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
26+
<html><body><p id="x">foo</p></body></html>
27+
28+
<?xml version="1.0" encoding="UTF-8"?>
29+
<root><child xmlns="urn:a"/></root>

0 commit comments

Comments
 (0)