From 3be6ff66b8e07a61fd906f4d1e83a908885c43b2 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 3 Oct 2024 08:34:50 +0200 Subject: [PATCH] Fix GH-16190: Using reflection to call Dom\Node::__construct causes assertion failure Closes GH-16193. --- NEWS | 2 ++ ext/dom/node.c | 2 +- ext/dom/tests/gh16190.phpt | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ext/dom/tests/gh16190.phpt diff --git a/NEWS b/NEWS index d46c2514dde..6f54180df20 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,8 @@ PHP NEWS DOMElement->getAttributeNames()). (nielsdos) . Fixed bug GH-16151 (Assertion failure in ext/dom/parentnode/tree.c). (nielsdos) + . Fixed bug GH-16190 (Using reflection to call Dom\Node::__construct + causes assertion failure). (nielsdos) - FPM: . Fixed bug GHSA-865w-9rf3-2wh5 (Logs from childrens may be altered). diff --git a/ext/dom/node.c b/ext/dom/node.c index 803237d96fb..5d4f0144c67 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -2548,7 +2548,7 @@ PHP_METHOD(Dom_Node, compareDocumentPosition) PHP_METHOD(Dom_Node, __construct) { - ZEND_UNREACHABLE(); + zend_throw_error(NULL, "Cannot directly construct %s, use document methods instead", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); } PHP_METHOD(DOMNode, __sleep) diff --git a/ext/dom/tests/gh16190.phpt b/ext/dom/tests/gh16190.phpt new file mode 100644 index 00000000000..d3d83b5eb49 --- /dev/null +++ b/ext/dom/tests/gh16190.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-16190 (Using reflection to call Dom\Node::__construct causes assertion failure) +--EXTENSIONS-- +dom +--FILE-- +invoke($doc); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Cannot directly construct Dom\XMLDocument, use document methods instead