Skip to content

Make cloning DOM node lists, maps, and collections fail #19089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ PHP 8.5 UPGRADE NOTES
change, but should more closely match user expectations, demonstrated by
GH-15753 and GH-16198.

- DOM:
. Cloning a DOMNamedNodeMap, DOMNodeList, Dom\NamedNodeMap, Dom\NodeList,
Dom\HTMLCollection, and Dom\DtdNamedNodeMap. This never actually resulted
in a working object, so the impact should actually be zero.
Comment on lines +49 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing some words in the upgrading entry.


- FileInfo:
. finfo_file() and finfo::file() now throws a ValueError instead of a
TypeError when $filename contains nul bytes.
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ PHP_MINIT_FUNCTION(dom)
dom_nnodemap_object_handlers.free_obj = dom_nnodemap_objects_free_storage;
dom_nnodemap_object_handlers.read_dimension = dom_nodemap_read_dimension;
dom_nnodemap_object_handlers.has_dimension = dom_nodemap_has_dimension;
dom_nnodemap_object_handlers.clone_obj = NULL;

memcpy(&dom_nodelist_object_handlers, &dom_nnodemap_object_handlers, sizeof(zend_object_handlers));
dom_nodelist_object_handlers.read_dimension = dom_nodelist_read_dimension;
Expand All @@ -823,7 +824,6 @@ PHP_MINIT_FUNCTION(dom)
dom_html_collection_object_handlers.read_dimension = dom_html_collection_read_dimension;
dom_html_collection_object_handlers.has_dimension = dom_html_collection_has_dimension;
dom_html_collection_object_handlers.get_gc = dom_html_collection_get_gc;
dom_html_collection_object_handlers.clone_obj = NULL;

memcpy(&dom_object_namespace_node_handlers, &dom_object_handlers, sizeof(zend_object_handlers));
dom_object_namespace_node_handlers.offset = XtOffsetOf(dom_object_namespace_node, dom.std);
Expand Down
50 changes: 50 additions & 0 deletions ext/dom/tests/clone_list_map_collection.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
Cloning node lists, maps, and collections should fail
--EXTENSIONS--
dom
--FILE--
<?php

$dom = new DOMDocument;
$dom->loadXML('<root a="1"><a/></root>');
try {
clone $dom->documentElement->attributes;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
clone $dom->documentElement->childNodes;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

$dom = Dom\XMLDocument::createFromString('<!DOCTYPE root [<!ENTITY foo "">]><root a="1"><a/></root>');
try {
clone $dom->documentElement->attributes;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
clone $dom->documentElement->childNodes;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
clone $dom->documentElement->children;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
clone $dom->doctype->entities;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Trying to clone an uncloneable object of class DOMNamedNodeMap
Trying to clone an uncloneable object of class DOMNodeList
Trying to clone an uncloneable object of class Dom\NamedNodeMap
Trying to clone an uncloneable object of class Dom\NodeList
Trying to clone an uncloneable object of class Dom\HTMLCollection
Trying to clone an uncloneable object of class Dom\DtdNamedNodeMap