From: mr dot heat at gmx dot de Operating system: Windows 2000 PHP version: Irrelevant PHP Bug Type: Filesystem function related Bug description: fgetcsv() not binary-safe on null bytes
Description: ------------ If the .csv file contains any 0x00 character, fgetcsv() stops reading the line and continues on the next one. Assume the folowing .csv file (with _ as place marker for the 0x00 character). "aaaaa","bb_bb" "ccccc","ddddd" fgetcsv() breaks at 0x00 (with slightly different behaviours in 4.x and 5.x), the EOL character is skipped, the '"' in front of 'ccccc' becomes the closing enclosure, 'ccccc' is skipped, 'ddddd' becomes value [2]. (This bug may be related to http://bugs.php.net/bug.php?id=22382 - see the last comment.) Reproduce code: --------------- <?php $fp = fopen("temporary.csv", "w+b"); fwrite($fp, "\"aaaaa\",\"bb" . chr(0) . "bb\"\n"); fwrite($fp, "\"ccccc\",\"ddddd\"\n"); fseek($fp, 0); var_dump(fgetcsv($fp, 100)); ?> Expected result: ---------------- array(3) { [0]=> string(5) "aaaaa" [1]=> string(5) "bb_bb" } (_ as a place marker for 0x00.) Actual result: -------------- In 4.3.4RC3-dev: array(3) { [0]=> string(5) "aaaaa" [1]=> string(2) "bb" [2]=> string(5) "ddddd" } In 5.0.0b2-dev (_ as a place marker for 0x00): array(3) { [0]=> string(5) "aaaaa" [1]=> string(7) "bb_bb" " [2]=> string(5) "ddddd" } -- Edit bug report at http://bugs.php.net/?id=26003&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26003&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26003&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26003&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26003&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26003&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=26003&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26003&r=support Expected behavior: http://bugs.php.net/fix.php?id=26003&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26003&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26003&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26003&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26003&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26003&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26003&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26003&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26003&r=float