Edit report at http://bugs.php.net/bug.php?id=54470&edit=1

 ID:                 54470
 Updated by:         il...@php.net
 Reported by:        RQuadling at GMail dot com
 Summary:            array_walk_recursive corruption
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   Windows XP SP3
 PHP Version:        5.3.6
-Assigned To:        
+Assigned To:        iliaa
 Block user comment: N
 Private report:     N

 New Comment:

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2011-04-11 13:35:05] RQuadling at GMail dot com

This seems to be fixes now via http://svn.php.net/viewvc?

view=revision&sortby=file&revision=310050

------------------------------------------------------------------------
[2011-04-05 15:33:03] RQuadling at GMail dot com

Description:
------------
I'm getting the crash in 5.3.6 and 5.3.7-dev from SVN.



The initial code was part of an exception handler and its purpose was to


generate a nicely formatted plain-text message to be emailed to me when
there 

was an exception.



I've reduced the code to the following example. No extensions required.



Tested with 5.3.0 - 5.3.5 - all working fine.

Tested with 5.3.6 and my own build 5.3.7-dev - crash.



The specifics of this code is to take an array (a stripped down stack
trace), 

and pad the elements so that they can be written out in a "table"
format, all 

nicely 

vertically aligned.



The crash comes during shutdown, not whilst running my code.



Depending upon the amount of additional code, I can either get corrupted
output 

or a crash.



The "Expected result" below is for PHP 5.3.5 and the "Actual result"
below is 

for PHP 5.3.6. Both are the official builds with no php.ini loaded.



The current example just outputs corrupted data.



Adding more code often results in an access violation.

Test script:
---------------
<?php

function arrayPad(array &$data, array $alignments, array &$widths =
Null) {

        $widths = array('name' => 7, 'age' => 2);

        echo 'Widths within ', __FUNCTION__, ' before array_walk_recursive ',
var_export($widths, True), PHP_EOL;

        $b_Result = array_walk_recursive($data, function(&$value, $key)
use($widths, $alignments) {

                $value = str_pad($value, $widths[$key], ' ', 
isset($alignments[$key])
? $alignments[$key] : STR_PAD_RIGHT);

        });

        echo 'Widths within ', __FUNCTION__, ' after array_walk_recursive ',
var_export($widths, True), PHP_EOL;

        return $b_Result;

}



$alignments = array('age' => STR_PAD_LEFT); // Force the age to be right
aligned.

$data = array( // A list of names and ages.

        array('name' => 'Richard', 'age' => 43,),

        array('name' => 'Oscar',   'age' => 2,),

);

arrayPad($data, $alignments, $widths);

echo 'The data ', var_export($data, True), PHP_EOL, 'The alignments ',
var_export($alignments, True), PHP_EOL, 'The widths returned by arrayPad
', var_export($widths, True);



Expected result:
----------------
php-5.3.5\php -n -f err_001.php

Widths within arrayPad before array_walk_recursive array (

  'name' => 7,

  'age' => 2,

)

Widths within arrayPad after array_walk_recursive array (

  'name' => 7,

  'age' => 2,

)

The data array (

  0 =>

  array (

    'name' => 'Richard',

    'age' => '43',

  ),

  1 =>

  array (

    'name' => 'Oscar  ',

    'age' => ' 2',

  ),

)

The alignments array (

  'age' => 0,

)

The widths returned by arrayPad array (

  'name' => 7,

  'age' => 2,

)

Actual result:
--------------
php-5.3.6\php -n -f err_001.php

Widths within arrayPad before array_walk_recursive array (

  'name' => 7,

  'age' => 2,

)

Widths within arrayPad after array_walk_recursive !   1  
└↨▲☺☺       ♥           

◄   !   Rich

The data array (

  0 =>

  array (

    'name' => 'Richard',

    'age' => '43',

  ),

  1 =>

  array (

    'name' => 'Oscar  ',

    'age' => ' 2',

  ),

)

The alignments array (

  'age' => 0,

)

The widths returned by arrayPad array (

)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54470&edit=1

Reply via email to