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

 ID:                 55660
 Comment by:         rewilliams at crystaltech dot com
 Reported by:        rewilliams at crystaltech dot com
 Summary:            SplFixedArray::fromArray causing segmentation fault
                     11
 Status:             Feedback
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   Mac OS X 10.7.1
 PHP Version:        5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

laruence@: I just caught that you stated your test file had 1005 lines. I'm not 
sure if you misread what I wrote or if you mistyped what you tested, but the 
test file I used was 10005 lines - you're off by an order of magnitude.

I uploaded my file to Dropbox. You can grab it here:

<http://dl.dropbox.com/u/9434155/data.csv>

If you're able to grab it and attach it to the bug or make it available 
someplace more permanent, that would be great.


Previous Comments:
------------------------------------------------------------------------
[2011-09-12 18:00:42] rewilliams at crystaltech dot com

FWIW, I just reproduced it on a Linux server running 5.3.4. I'm working on 
getting 
a backtrace, but I need to build a debug version of PHP first.

------------------------------------------------------------------------
[2011-09-10 03:59:47] larue...@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

I can not reproduce it with a test csv file(1005 line, 13 cloumns) with 5.3 
trunk

------------------------------------------------------------------------
[2011-09-09 21:32:23] rewilliams at crystaltech dot com

Hmm, I don't see how to upload reproduction scripts. The script is below; I'll 
leave the data 
file to the tester. I created a simple CSV file that had 10,005 lines of 13 
columns each, where 
the value of every column is the alphabet. It included one trailing blank line 
and used CRLF line 
endings.

Here's the script:

<?php

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL | E_STRICT);

class NmsObj {
        static public function ImportData($whichOption) {
                $fileObj = new SplFileObject('TestData.csv');
                $fileObj->setFlags(SplFileObject::SKIP_EMPTY | 
SplFileObject::DROP_NEW_LINE | 
SplFileObject::READ_CSV);

                $return = array();
                foreach ($fileObj as $oneLine) {
                        $return[] = new stdClass();
                } //foreach

                switch ($whichOption) {
                        case 1:
                                $return = array_slice($return, 0, 9999);
                                $result = SplFixedArray::fromArray($return);
                                //we get here
                                return $result;
                        break;

                        case 2:
                                $return = array_slice($return, 0, 10000);
                                $result = SplFixedArray::fromArray($return);
                                //we won't get here - get "Segmentation fault: 
11"
                                return $result;
                        break;
                } //switch
        } //ImportData
} //NmsObj

//$dataSet1 = NmsObj::ImportData(1);
$dataSet1 = NmsObj::ImportData(2);

echo "Done!\n";

?>

------------------------------------------------------------------------
[2011-09-09 21:26:12] rewilliams at crystaltech dot com

Description:
------------
I created a script that uses SplFileObject to iterate over a CSV file. As it 
goes, it creates a new object with each line's data and adds the object to an 
array. Running it with 10k or more lines crashes with a "Segmentation fault: 
11" 
error message, while anything up to 9,999 lines works well. Adjusting PHP's 
memory limit had no effect.

I've attached a partial reduction to this bug. It seems like I really need the 
elements of the SplFileObject and the class for each line, as skipping either 
one of those (even when the resulting array is much larger than 10k items) 
causes the failure to disappear. I'm not sure exactly what the trigger is, 
however. My reduction includes a sample CSV file of just over 10k lines, and 
though it still uses SplFileObject and a per-line object, the class for the 
latter is just an stdClass, and the data from the file is essentially ignored.

The script has two lines near the bottom that are method calls to ImportData(). 
Comment out one or the other to see the script run successfully or to see it 
fail. Option 1 works; option 2 fails.

Note that I tested this under 5.3.6, not the 5.3.8 that's indicated on the bug. 
I do not have access to the latter.

Expected result:
----------------
I'd expect the script to run to completion in all cases, assuming there is 
sufficient memory.

Actual result:
--------------
The script fails in the case of >= 10000 items in the array being converted.


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



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

Reply via email to