From 6d215981b6f8cb0f81c17a334247af942b5cdd8c Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:28:02 +0100 Subject: [PATCH] Fix GH-17397: Assertion failure ext/dom/php_dom.c The problem was that the property hash tables were not merging the correct ones, a stupid typo (or caused by merging). Closes GH-17406. --- NEWS | 3 + ext/dom/php_dom.c | 4 +- ext/dom/tests/gh17397.phpt | 16 ++++ ...ent_implementation_createDocumentType.phpt | 96 +++++++------------ ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt | 28 ++---- 5 files changed, 63 insertions(+), 84 deletions(-) create mode 100644 ext/dom/tests/gh17397.phpt diff --git a/NEWS b/NEWS index 18af0686018..55d58170fd7 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ PHP NEWS . Fixed bug GH-17234 (Numeric parent hook call fails with assertion). (nielsdos) +- DOM: + . Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos) + - FTP: . Fixed bug GH-16800 (ftp functions can abort with EINTR). (nielsdos) diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 9c1dc5f61d3..6f9d87feebf 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -1080,7 +1080,7 @@ PHP_MINIT_FUNCTION(dom) DOM_REGISTER_PROP_HANDLER(&dom_modern_attr_prop_handlers, "value", dom_attr_value_read, dom_attr_value_write); DOM_REGISTER_PROP_HANDLER(&dom_modern_attr_prop_handlers, "ownerElement", dom_attr_owner_element_read, NULL); DOM_REGISTER_PROP_HANDLER(&dom_modern_attr_prop_handlers, "specified", dom_attr_specified_read, NULL); - zend_hash_merge(&dom_modern_attr_prop_handlers, &dom_node_prop_handlers, NULL, false); + zend_hash_merge(&dom_modern_attr_prop_handlers, &dom_modern_node_prop_handlers, NULL, false); DOM_OVERWRITE_PROP_HANDLER(&dom_modern_attr_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write); DOM_OVERWRITE_PROP_HANDLER(&dom_modern_attr_prop_handlers, "textContent", dom_node_text_content_read, dom_node_text_content_write); zend_hash_add_new_ptr(&classes, dom_modern_attr_class_entry->name, &dom_modern_attr_prop_handlers); @@ -1194,7 +1194,7 @@ PHP_MINIT_FUNCTION(dom) DOM_REGISTER_PROP_HANDLER(&dom_modern_documenttype_prop_handlers, "publicId", dom_documenttype_public_id_read, NULL); DOM_REGISTER_PROP_HANDLER(&dom_modern_documenttype_prop_handlers, "systemId", dom_documenttype_system_id_read, NULL); DOM_REGISTER_PROP_HANDLER(&dom_modern_documenttype_prop_handlers, "internalSubset", dom_documenttype_internal_subset_read, NULL); - zend_hash_merge(&dom_modern_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, false); + zend_hash_merge(&dom_modern_documenttype_prop_handlers, &dom_modern_node_prop_handlers, NULL, false); zend_hash_add_new_ptr(&classes, dom_modern_documenttype_class_entry->name, &dom_modern_documenttype_prop_handlers); dom_notation_class_entry = register_class_DOMNotation(dom_node_class_entry); diff --git a/ext/dom/tests/gh17397.phpt b/ext/dom/tests/gh17397.phpt new file mode 100644 index 00000000000..83d7beab907 --- /dev/null +++ b/ext/dom/tests/gh17397.phpt @@ -0,0 +1,16 @@ +--TEST-- +GH-17397 (Assertion failure ext/dom/php_dom.c) +--EXTENSIONS-- +dom +--FILE-- +'); +var_dump($dom->doctype->prefix); +echo $dom->saveXml(); +?> +--EXPECTF-- +Warning: Undefined property: Dom\DocumentType::$prefix in %s on line %d +NULL + + + diff --git a/ext/dom/tests/modern/spec/Document_implementation_createDocumentType.phpt b/ext/dom/tests/modern/spec/Document_implementation_createDocumentType.phpt index 88c66abf09c..bfb150b5cca 100644 --- a/ext/dom/tests/modern/spec/Document_implementation_createDocumentType.phpt +++ b/ext/dom/tests/modern/spec/Document_implementation_createDocumentType.phpt @@ -25,7 +25,7 @@ foreach ($test_matrix as $test_item) { ?> --EXPECT-- -object(Dom\DocumentType)#3 (23) { +object(Dom\DocumentType)#3 (19) { ["name"]=> string(5) "qname" ["entities"]=> @@ -38,12 +38,14 @@ object(Dom\DocumentType)#3 (23) { string(6) "system" ["internalSubset"]=> NULL - ["nodeName"]=> - string(5) "qname" - ["nodeValue"]=> - NULL ["nodeType"]=> int(10) + ["nodeName"]=> + string(5) "qname" + ["baseURI"]=> + NULL + ["isConnected"]=> + bool(false) ["parentNode"]=> NULL ["parentElement"]=> @@ -58,17 +60,7 @@ object(Dom\DocumentType)#3 (23) { NULL ["nextSibling"]=> NULL - ["attributes"]=> - NULL - ["isConnected"]=> - bool(false) - ["namespaceURI"]=> - NULL - ["prefix"]=> - string(0) "" - ["localName"]=> - NULL - ["baseURI"]=> + ["nodeValue"]=> NULL ["textContent"]=> string(0) "" @@ -76,7 +68,7 @@ object(Dom\DocumentType)#3 (23) { -object(Dom\DocumentType)#2 (23) { +object(Dom\DocumentType)#2 (19) { ["name"]=> string(5) "qname" ["entities"]=> @@ -89,12 +81,14 @@ object(Dom\DocumentType)#2 (23) { string(0) "" ["internalSubset"]=> NULL - ["nodeName"]=> - string(5) "qname" - ["nodeValue"]=> - NULL ["nodeType"]=> int(10) + ["nodeName"]=> + string(5) "qname" + ["baseURI"]=> + NULL + ["isConnected"]=> + bool(false) ["parentNode"]=> NULL ["parentElement"]=> @@ -109,17 +103,7 @@ object(Dom\DocumentType)#2 (23) { NULL ["nextSibling"]=> NULL - ["attributes"]=> - NULL - ["isConnected"]=> - bool(false) - ["namespaceURI"]=> - NULL - ["prefix"]=> - string(0) "" - ["localName"]=> - NULL - ["baseURI"]=> + ["nodeValue"]=> NULL ["textContent"]=> string(0) "" @@ -127,7 +111,7 @@ object(Dom\DocumentType)#2 (23) { -object(Dom\DocumentType)#1 (23) { +object(Dom\DocumentType)#1 (19) { ["name"]=> string(5) "qname" ["entities"]=> @@ -140,12 +124,14 @@ object(Dom\DocumentType)#1 (23) { string(6) "system" ["internalSubset"]=> NULL - ["nodeName"]=> - string(5) "qname" - ["nodeValue"]=> - NULL ["nodeType"]=> int(10) + ["nodeName"]=> + string(5) "qname" + ["baseURI"]=> + NULL + ["isConnected"]=> + bool(false) ["parentNode"]=> NULL ["parentElement"]=> @@ -160,17 +146,7 @@ object(Dom\DocumentType)#1 (23) { NULL ["nextSibling"]=> NULL - ["attributes"]=> - NULL - ["isConnected"]=> - bool(false) - ["namespaceURI"]=> - NULL - ["prefix"]=> - string(0) "" - ["localName"]=> - NULL - ["baseURI"]=> + ["nodeValue"]=> NULL ["textContent"]=> string(0) "" @@ -178,7 +154,7 @@ object(Dom\DocumentType)#1 (23) { -object(Dom\DocumentType)#4 (23) { +object(Dom\DocumentType)#4 (19) { ["name"]=> string(5) "qname" ["entities"]=> @@ -191,12 +167,14 @@ object(Dom\DocumentType)#4 (23) { string(0) "" ["internalSubset"]=> NULL - ["nodeName"]=> - string(5) "qname" - ["nodeValue"]=> - NULL ["nodeType"]=> int(10) + ["nodeName"]=> + string(5) "qname" + ["baseURI"]=> + NULL + ["isConnected"]=> + bool(false) ["parentNode"]=> NULL ["parentElement"]=> @@ -211,17 +189,7 @@ object(Dom\DocumentType)#4 (23) { NULL ["nextSibling"]=> NULL - ["attributes"]=> - NULL - ["isConnected"]=> - bool(false) - ["namespaceURI"]=> - NULL - ["prefix"]=> - string(0) "" - ["localName"]=> - NULL - ["baseURI"]=> + ["nodeValue"]=> NULL ["textContent"]=> string(0) "" diff --git a/ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt b/ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt index c94dce263ef..fb0853939f8 100644 --- a/ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt +++ b/ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt @@ -26,7 +26,7 @@ var_dump($doctype->notations["GIF"]); ?> --EXPECTF-- -object(Dom\DocumentType)#2 (24) { +object(Dom\DocumentType)#2 (20) { ["name"]=> string(4) "root" ["entities"]=> @@ -41,12 +41,16 @@ object(Dom\DocumentType)#2 (24) { string(105) " " - ["nodeName"]=> - string(4) "root" - ["nodeValue"]=> - NULL ["nodeType"]=> int(10) + ["nodeName"]=> + string(4) "root" + ["baseURI"]=> + string(%d) "%s" + ["isConnected"]=> + bool(true) + ["ownerDocument"]=> + string(22) "(object value omitted)" ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> @@ -61,20 +65,8 @@ object(Dom\DocumentType)#2 (24) { NULL ["nextSibling"]=> string(22) "(object value omitted)" - ["attributes"]=> + ["nodeValue"]=> NULL - ["isConnected"]=> - bool(true) - ["ownerDocument"]=> - string(22) "(object value omitted)" - ["namespaceURI"]=> - NULL - ["prefix"]=> - string(0) "" - ["localName"]=> - NULL - ["baseURI"]=> - string(%d) "%s" ["textContent"]=> NULL }