Bug #14749 Updated: array_reduce() causes segmentation faults

From: Date: Thu, 04 Jul 2002 22:14:50 +0000
Subject: Bug #14749 Updated: array_reduce() causes segmentation faults
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-13158@lists.php.net to get a copy of this message
ID: 14749 Updated by: eru@php.net Reported By: dave@ovumdesign.com -Status: Open +Status: Bogus Bug Type: Reproducible crash Operating System: RedHat 7.1 PHP Version: 4.1.1 New Comment: Thank you for taking the time to report a problem with PHP. Unfortunately your are not using a current version of PHP -- the problem might already be fixed. Please download a new PHP version from http://www.php.net/downloads.php If you are able to reproduce the bug with one of the latest versions of PHP, please change the PHP version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PHP. Previous Comments: ------------------------------------------------------------------------ [2002-02-12 13:53:07] dave@ovumdesign.com Configure line: './configure' '--with-apxs' '--with-mysql=/usr' '--with-xml' '--enable-wddx' '--with-imap' '--with-gdbm' ------------------------------------------------------------------------ [2002-02-11 23:12:07] elixer@php.net Can you attach a copy of tree.xml to an email and send it to elixer@php.net? Also, please update this bug report to include your configure line. Sean ------------------------------------------------------------------------ [2001-12-28 17:27:13] dave@ovumdesign.com This drove me crazy. array_reduce() causes segmentation faults when used in a complex, recursive manner. I'm pretty sure it's array_reduce() and not create_function() that's the culprit here. I'm sorry I can't provide a simpler example, but I've been unable to reprodce the crash otherwise. I'll try to describe what I'm doing to the best of my abilities. debug.php is an include that I use for dumping out nicely-formatted data structures - it works like print_r() but cleaner. It's written using functional techniques, so I'm using create_function() as a lambda and array_reduce() as a reduction. tree.xml is an XML file that I'm parsing into a data structure using wddx_deserialize(). I thought that it was my deserialization that was the problem when I was using XML-RPC, and switched to WDDX in hopes that that would solve the crash problem. It didn't. It took a lot of monkeying around before I figured out where the real problem was. I don't know how to use GDB, and I don't really have any more time to dedicate to this, so no backtrace. Sorry. I've experienced this problem with PHP 4.1.0, 4.1.1, and 4.2.0-dev under RedHat 7.1 and Apache 1.3.22. Here are my source files: crash.php (this is the one to run) <pre> <?php require_once 'debug.php'; $data = wddx_deserialize(join('', file('tree.xml'))); // This works. print_r($data); // This doesn't. //debug($data); ?> </pre> debug.php: <?php function array_items($array) { $result = array(); foreach ($array as $key => $val) $result[] = array($key, $val); return $result; } function debug_node($key, $val) { return "-+ <font color=\"#ad0000\"><b>$key</b></font> " . "<font color=\"#505050\">(" . gettype($val) . ")</font><br>\n"; } function debug_leaf($key, $val) { return "-> <b>$key</b> = <font color=\"#0000ad\">$val</font> " . "<font color=\"#505050\">(" . gettype($val) . ")</font><br>\n"; } function debug_reduce($prep, $accum, $key_val) { list($key, $val) = $key_val; return "$accum$prep" . (is_array($val) ? debug_node($key, $val) . debug_tree("$prep |", $val) : debug_leaf($key, $val)); } function debug_tree($prep, $array) { return array_reduce(array_items($array), create_function('$a, $x', "return debug_reduce('$prep', \$a, \$x);"), ''); } function debug_array($array) { return "<font face=\"arial\" size=3 color=\"black\"><code>\n" . debug_tree('|', $array) . '</code></font>'; } function debug_string($string) { return "<font face=\"arial\" size=2 color=\"black\">\n" . nl2br($string) . "</font>\n"; } function debug($msg) { ?> <table width="100%" border=0 cellpadding=5 cellspacing=0 bgcolor="#dedede" bordercolor="black"><td> <?=(is_array($msg) or is_object($msg)) ? debug_array($msg) : debug_string($msg)?> </td></table> <table width="100%" height=1 cellpadding=0 cellspacing=0 bgcolor="black"><td></td></table> <? return $msg; } ?> tree.xml: <?xml version="1.0"?><!DOCTYPE wddxPacket SYSTEM "../static/wddx_0090.dtd"><wddxPacket version="0.9"><header/><data><array length=" 4"><struct><var name="label"><string>About Us</string></var><var name="children"><array length="2"><struct><var name="label"><strin g>Who We Are</string></var><var name="children"><array length="0"></array></var><var name="path"><string>about/who</string></var><v ar name="content"><array length="2"><number>23</number><number>42</number></array></var></struct><struct><var name="label"><string> What We Doodoo</string></var><var name="children"><array length="0"></array></var><var name="path"><string>about/what</string></var ><var name="content"><array length="1"><number>69</number></array></var></struct></array></var><var name="path"><string>about</stri ng></var><var name="content"><array length="0"></array></var></struct><struct><var name="label"><string>Products</string></var><var name="children"><array length="0"></array></var><var name="path"><string>products</string></var><var name="content"><array length= "2"><number>86</number><number>99</number></array></var></struct><struct><var name="label"><string>Services</string></var><var name ="children"><array length="0"></array></var><var name="path"><string>services</string></var><var name="content"><array length="0">< /array></var></struct><struct><var name="label"><string>Contact Us</string></var><var name="children"><array length="0"></array></v ar><var name="path"><string>contact</string></var><var name="content"><array length="1"><number>1</number></array></var></struct></ array></data></wddxPacket> That's it. Good luck. Peace, Dave ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=14749&edit=1

« previous php.bugs (#13158) next »