php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42968 DOMXML functions can allocate more memory than memory_limit allows
Submitted: 2007-10-15 08:31 UTC Modified: 2007-10-16 13:57 UTC
Votes:8
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:0 (0.0%)
From: quaker at barbara dot eu dot org Assigned:
Status: Wont fix Package: DOM XML related
PHP Version: 5.2.4 OS: Linux 2.6.20, Ubuntu 7.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: quaker at barbara dot eu dot org
New email:
PHP Version: OS:

 

 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-15 20:28 UTC] 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-16 04:42 UTC] quaker at barbara dot eu dot org
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);
 [2007-10-16 13:57 UTC] rrichards@php.net
It does exist. dom binding is much more efficient than domxml so you dont hit the PHP memory limit.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 11:01:27 2024 UTC