#42968 [WFx]: DOMXML functions can allocate more memory than memory_limit allows

From: Date: Tue, 16 Oct 2007 04:42:44 +0000
Subject: #42968 [WFx]: DOMXML functions can allocate more memory than memory_limit allows
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118579@lists.php.net to get a copy of this message
ID: 42968 User updated by: quaker at barbara dot eu dot org Reported By: quaker at barbara dot eu dot org Status: Wont fix Bug Type: DOM XML related Operating System: Linux 2.6.20, Ubuntu 7.04 PHP Version: 5.2.4 New Comment: 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); Previous Comments: ------------------------------------------------------------------------ [2007-10-15 20:28:26] rrichards@php.net That memory is handled from within the libxml2 library. There is no safe way to integrate the memory routines from PHP without adversely affecting all other modules within the web server that rely on libxml2. ------------------------------------------------------------------------ [2007-10-15 08:31:32] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42968&edit=1

« previous php.bugs (#118579) next »