cvs: php4(PHP_4_3) /ext/standard file.c /ext/standard/tests/file bug12556.phpt test.csv

From: Date: Thu, 05 Dec 2002 20:05:20 +0000
Subject: cvs: php4(PHP_4_3) /ext/standard file.c /ext/standard/tests/file bug12556.phpt test.csv
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-16942@lists.php.net to get a copy of this message
iliaa Thu Dec 5 15:05:20 2002 EDT Added files: (Branch: PHP_4_3) /php4/ext/standard/tests/file test.csv bug12556.phpt Modified files: /php4/ext/standard file.c Log: MFH Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.279.2.2 php4/ext/standard/file.c:1.279.2.3 --- php4/ext/standard/file.c:1.279.2.2 Sat Nov 30 14:13:28 2002 +++ php4/ext/standard/file.c Thu Dec 5 15:05:19 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.279.2.2 2002/11/30 19:13:28 iliaa Exp $ */ +/* $Id: file.c,v 1.279.2.3 2002/12/05 20:05:19 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -2109,7 +2109,7 @@ /* first section exactly as php_fgetss */ zval **fd, **bytes, **p_delim, **p_enclosure; - int len; + int len, temp_len; char *buf; php_stream *stream; @@ -2194,7 +2194,8 @@ /* reserve workspace for building each individual field */ - temp = emalloc(len); /* unlikely but possible! */ + temp_len = len; + temp = emalloc(temp_len + 1); /* unlikely but possible! */ tptr = temp; /* Initialize return array */ @@ -2209,7 +2210,7 @@ /* 2. Read field, leaving bptr pointing at start of next field */ if (enclosure && *bptr == enclosure) { bptr++; /* move on to first character in field */ - + /* 2A. handle enclosure delimited field */ while (*bptr) { if (*bptr == enclosure) { @@ -2236,6 +2237,13 @@ memset(buf, 0, len+1); if (php_stream_gets(stream, buf, len) == NULL) { + /* we've got an unterminated enclosure, assign all the data + * from the start of the enclosure to end of data to the last element + */ + if (temp_len > len) { + break; + } + efree(lineEnd); efree(temp); efree(buf); @@ -2243,6 +2251,8 @@ RETURN_FALSE; } + temp_len += len; + temp = erealloc(temp, temp_len+1); bptr = buf; tptr = buf + strlen(buf) -1; while (isspace((int) *tptr) && (*tptr!=delimiter) && (tptr > bptr)) Index: php4/ext/standard/tests/file/test.csv +++ php4/ext/standard/tests/file/test.csv 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 Index: php4/ext/standard/tests/file/bug12556.phpt +++ php4/ext/standard/tests/file/bug12556.phpt --TEST-- Bug #12556: fgetcvs ignores lengths when quotes not closed --POST-- --GET-- --FILE-- <?php $fp=fopen(dirname(__FILE__)."/test.csv", "r"); while($line=fgetcsv($fp, 24)){ print("Read 24 bytes\n"); } ?> --EXPECT-- Read 24 bytes Read 24 bytes Read 24 bytes Read 24 bytes Read 24 bytes Read 24 bytes Read 24 bytes Read 24 bytes Read 24 bytes

« previous php.cvs (#16942) next »