php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12556 fgetcsv ignores length if quotes not closed
Submitted: 2001-08-03 12:45 UTC Modified: 2002-12-05 14:10 UTC
From: brianm at dealnews dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.0-dev OS: Linux
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: brianm at dealnews dot com
New email:
PHP Version: OS:

 

 [2001-08-03 12:45 UTC] brianm at dealnews dot com
Ok, I can live with the embedded newlines in fgetcsv even though I think it is wrong.  No other app will read a csv file this way.  MySQL for example exports a literal \n for newlines and translates them on import rather than embedding them.

But, I do think the length should be respected no matter what:

data:
-----------------
6,7,8,line1
1,2,3,"line2
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3

script:
---------------
    $fp=fopen("test.csv", "r");
    while($line=fgetcsv($fp, 24)){
        print_r($line);
    }


Nothing after that quote gets read.  Even after 24 bites have been read.

It would seem to me that the code which reads an additional line if an embedded newline is reached should not issue an FP_FGETS with len but should use len-strlen(temp).  This would make the length param make more sense.  And then if len was met it should terminate the record and start all over.

The code in this function is less that understandable with all the great names like buff and temp floating around.  I tried looking at it but will leave it to the guys who wrote it.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-11 03:05 UTC] sniper@php.net
This example of yours actually crashes with current HEAD..

(gdb) bt
#0  0x4192fdc9 in memchr () from /lib/libc.so.6
#1  0x8559784 in ?? () at md4.c:255
#2  0x41922fa6 in _IO_getline (fp=0x855dd58, buf=0x8559784 "", n=23, delim=10, extract_delim=1) at iogetline.c:39
#3  0x419227a0 in _IO_fgets (buf=0x8559784 "", n=24, fp=0x855dd58) at iofgets.c:48
#4  0x82450bd in php_stdiop_gets (stream=0x855e894, buf=0x8559784 "", size=24)
    at /usr/src/web/php/php4/main/streams.c:696
#5  0x8243e34 in _php_stream_gets (stream=0x855e894, buf=0x8559784 "", maxlen=24)
    at /usr/src/web/php/php4/main/streams.c:248
#6  0x81cb335 in zif_fgetcsv (ht=2, return_value=0x855e2ac, this_ptr=0x0, return_value_used=1)
    at /usr/src/web/php/php4/ext/standard/file.c:2070
#7  0x82828b7 in execute (op_array=0x85596fc) at /usr/src/web/php/php4/Zend/zend_execute.c:1587
#8  0x826fbc4 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/web/php/php4/Zend/zend.c:810
#9  0x8239951 in php_execute_script (primary_file=0xbffff95c) at /usr/src/web/php/php4/main/main.c:1388
#10 0x8288e07 in main (argc=2, argv=0xbffff9c4) at /usr/src/web/php/php4/sapi/cli/php_cli.c:674
#11 0x418e89cb in __libc_start_main (main=0x828829c <main>, argc=2, argv=0xbffff9c4, init=0x8086d78 <_init>, 
    fini=0x82fed04 <_fini>, rtld_fini=0x4000aea0 <_dl_fini>, stack_end=0xbffff9bc)
    at ../sysdeps/generic/libc-start.c:92

 [2002-08-18 02:56 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2002-12-05 10:32 UTC] brianlmoon@php.net
I just tested this with php4-200212051430 and it still segfaults.
 [2002-12-05 11:02 UTC] sniper@php.net
crashes here too..

 [2002-12-05 14:09 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC