Skip to content

Commit

Permalink
Mark DOM classes as not serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 10, 2021
1 parent 1c675b9 commit ca94d55
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function after(...$nodes): void;
public function replaceWith(...$nodes): void;
}

/** @not-serializable */
class DOMNode
{
/** @readonly */
Expand Down Expand Up @@ -155,6 +156,7 @@ public function removeChild(DOMNode $child) {}
public function replaceChild(DOMNode $node, DOMNode $child) {}
}

/** @not-serializable */
class DOMNameSpaceNode
{
/** @readonly */
Expand Down Expand Up @@ -654,6 +656,7 @@ public function __construct(string $name, string $value = "") {}
}

#ifdef LIBXML_XPATH_ENABLED
/** @not-serializable */
class DOMXPath
{
/** @readonly */
Expand Down
5 changes: 4 additions & 1 deletion ext/dom/php_dom_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 3db2a5e01c88b189f2d58aa67b598653ebde6a76 */
* Stub hash: cff5c4b824da940f151617d08bb6b2419a9d26e9 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 0)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
Expand Down Expand Up @@ -989,6 +989,7 @@ static zend_class_entry *register_class_DOMNode(void)

INIT_CLASS_ENTRY(ce, "DOMNode", class_DOMNode_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

zval property_nodeName_default_value;
ZVAL_UNDEF(&property_nodeName_default_value);
Expand Down Expand Up @@ -1103,6 +1104,7 @@ static zend_class_entry *register_class_DOMNameSpaceNode(void)

INIT_CLASS_ENTRY(ce, "DOMNameSpaceNode", class_DOMNameSpaceNode_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

zval property_nodeName_default_value;
ZVAL_UNDEF(&property_nodeName_default_value);
Expand Down Expand Up @@ -1654,6 +1656,7 @@ static zend_class_entry *register_class_DOMXPath(void)

INIT_CLASS_ENTRY(ce, "DOMXPath", class_DOMXPath_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

zend_string *property_document_class_DOMDocument = zend_string_init("DOMDocument", sizeof("DOMDocument")-1, 1);
zval property_document_default_value;
Expand Down
42 changes: 42 additions & 0 deletions ext/dom/tests/not_serializable.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
DOM classes are not serializable
--EXTENSIONS--
dom
--FILE--
<?php

$doc = new DOMDocument();
$doc->loadXML('<root><node/></root>');
try {
serialize($doc);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}

$node = $doc->documentElement;
try {
serialize($node);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}

$xpath = new DOMXPath($doc);
try {
serialize($xpath);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}

$ns = $xpath->query('//namespace::*')->item(0);
try {
serialize($ns);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Serialization of 'DOMDocument' is not allowed
Serialization of 'DOMElement' is not allowed
Serialization of 'DOMXPath' is not allowed
Serialization of 'DOMNameSpaceNode' is not allowed

0 comments on commit ca94d55

Please sign in to comment.