php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54470 array_walk_recursive corruption
Submitted: 2011-04-05 15:33 UTC Modified: 2011-04-12 20:22 UTC
From: RQuadling at GMail dot com Assigned: iliaa (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.3.6 OS: Windows XP SP3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2011-04-05 15:33 UTC] 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 (
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-11 13:35 UTC] 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-12 20:22 UTC] iliaa@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: iliaa
 [2011-04-12 20:22 UTC] iliaa@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 02:01:31 2024 UTC