|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-15 08:31 UTC] quaker at barbara dot eu dot org
Description:
------------
DOMXML functions can allocate more memory than memory_limit allows.
Reproduce code:
---------------
<?php
print "Current memory limit: " . ini_get("memory_limit") . "\n";
$dom = new DOMDocument();
$responseElement = $dom->createElement('response');
$dom->appendChild($responseElement);
/* Infinite loop */
while (1)
{
$dataElement = $dom->createElement('data');
$dataText = $dom->createTextNode('Example data');
$dataElement->appendChild($dataText);
$responseElement->appendChild($dataElement);
}
/* Never executed, just for showing idea */
$xmlString = $dom->saveXML();
echo $xmlString;
?>
Expected result:
----------------
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate XXX bytes) in YYY on line ZZZ
Actual result:
--------------
Memory limit is not hit. Script memory usage grows, till out of memory received from OS.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
How does this bug not exists in 4.4.7 while it uses same XML library? Below example code: <?php print "Current memory limit: " . ini_get("memory_limit") . "\n"; $dom = domxml_new_doc('1.0'); $responseElement = $dom->create_element('response'); $dom->append_child($responseElement); /* Infinite loop */ while (1) { $dataElement = $dom->create_element('data'); $dataText = $dom->create_text_node('Example data'); $dataElement->append_child($dataText); $responseElement->append_child($dataElement); } /* Never executed, just for showing idea */ $xmlString = $dom->dump_mem(true); echo $xmlString; ?> Result, as expected: Allowed memory size of 2097152 bytes exhausted (tried to allocate 32 bytes) in XXX on line 14 Line 14 is: $responseElement->append_child($dataElement);