Skip to content

Throw DomException for DOM out-of-memory error conditions #7049

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 3 commits 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
26 changes: 17 additions & 9 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ PHP_METHOD(DOMDocument, createElement)

node = xmlNewDocNode(docp, NULL, (xmlChar *) name, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ(node, &ret, intern);
Expand All @@ -558,9 +559,10 @@ PHP_METHOD(DOMDocument, createDocumentFragment)

DOM_GET_OBJ(docp, id, xmlDocPtr, intern);

node = xmlNewDocFragment(docp);
node = xmlNewDocFragment(docp);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ(node, &ret, intern);
Expand Down Expand Up @@ -589,7 +591,8 @@ PHP_METHOD(DOMDocument, createTextNode)

node = xmlNewDocText(docp, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ(node, &ret, intern);
Expand Down Expand Up @@ -618,7 +621,8 @@ PHP_METHOD(DOMDocument, createComment)

node = xmlNewDocComment(docp, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ(node, &ret, intern);
Expand Down Expand Up @@ -647,7 +651,8 @@ PHP_METHOD(DOMDocument, createCDATASection)

node = xmlNewCDataBlock(docp, (xmlChar *) value, value_len);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ(node, &ret, intern);
Expand Down Expand Up @@ -681,7 +686,8 @@ PHP_METHOD(DOMDocument, createProcessingInstruction)

node = xmlNewPI((xmlChar *) name, (xmlChar *) value);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

node->doc = docp;
Expand Down Expand Up @@ -717,7 +723,8 @@ PHP_METHOD(DOMDocument, createAttribute)

node = xmlNewDocProp(docp, (xmlChar *) name, NULL);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ((xmlNodePtr) node, &ret, intern);
Expand Down Expand Up @@ -752,7 +759,8 @@ PHP_METHOD(DOMDocument, createEntityReference)

node = xmlNewReference(docp, (xmlChar *) name);
if (!node) {
RETURN_FALSE;
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
RETURN_THROWS();
}

DOM_RET_OBJ((xmlNodePtr) node, &ret, intern);
Expand Down
6 changes: 3 additions & 3 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ public function createAttributeNS(?string $namespace, string $qualifiedName) {}
/** @return DOMCdataSection|false */
public function createCDATASection(string $data) {}

/** @return DOMComment|false */
/** @return DOMComment */
public function createComment(string $data) {}

/** @return DOMDocumentFragment|false */
/** @return DOMDocumentFragment */
public function createDocumentFragment() {}

/** @return DOMElement|false */
Expand All @@ -485,7 +485,7 @@ public function createEntityReference(string $name) {}
/** @return DOMProcessingInstruction|false */
public function createProcessingInstruction(string $target, string $data = "") {}

/** @return DOMText|false */
/** @return DOMText */
public function createTextNode(string $data) {}

/** @return DOMElement|null */
Expand Down
2 changes: 1 addition & 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: f9bcfaa9c0ed58949c4ee58fbf1833359010be7d */
* Stub hash: 6045721c540d168c7e2323b6c7b685c073d17971 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
Expand Down