|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-06 15:24 UTC] r dot korving at xit dot nl
Description:
------------
When I use the output of $xmlobject->xpath() in a preg_match("/whatever pattern/", $xpathoutput) it makes memory usage explode or the whole script segfaults.
The problem can be manually solved by typecasting the $xpathoutput to a string, but nonetheless, a segfault should never ever be desired behaviour. In fact, in one case I actually saw PHP tried to allocate over 1 gigabyte of memory.
Reproduce code:
---------------
#!/usr/bin/php5
<?
$xml = simplexml_load_file("test.xml");
$val = $xml->xpath("/rootelem/testelems");
for ($i=0; $i < 20; $i++)
{
if (preg_match("/abc/", $val[0]))
echo "Y";
else
echo "N";
}
?>
test.xml:
<rootelem>
<testelems>this is one</testelems>
<testelems>this is another one !</testelems>
</rootelem>
Expected result:
----------------
NNNNNNNNNNNNNNNNNNNN
Actual result:
--------------
NSegmentation fault
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 23:00:02 2025 UTC |
looks like an engine bug. when it parsers the arguments for a function and tries to do its auto string conversion magic, the zval gets hosed since it uses the zval as both the read and write object for the cast_object call in zend_parse_arg_impl. simple script: <?php $xml = new SimpleXMLElement("<test/>"); str_split($xml); // any function requiring string paremeter var_dump($xml); // $xml is foobar at this point ?>