moriyoshi Mon Oct 27 17:36:45 2003 EDT
Modified files:
/php-src/ext/standard file.c
Log:
Fixed bug #26003 (fgetcsv() not binary-safe on null bytes)
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.362 php-src/ext/standard/file.c:1.363
--- php-src/ext/standard/file.c:1.362 Sun Oct 5 09:59:15 2003
+++ php-src/ext/standard/file.c Mon Oct 27 17:36:44 2003
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.362 2003/10/05 13:59:15 moriyoshi Exp $ */
+/* $Id: file.c,v 1.363 2003/10/27 22:36:44 moriyoshi Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -1723,10 +1723,11 @@
static const char *php_fgetcsv_lookup_trailing_spaces(const char *ptr, size_t len,
const char delimiter TSRMLS_DC)
{
int inc_len;
- size_t cnt = 0;
+ unsigned char last_chars[2] = { 0, 0 };
while (len > 0) {
- switch ((inc_len = _php_mblen(ptr, len))) {
+ inc_len = (*ptr == '\0' ? 1: _php_mblen(ptr, len));
+ switch (inc_len) {
case -2:
case -1:
inc_len = 1;
@@ -1734,20 +1735,25 @@
case 0:
goto quit_loop;
case 1:
- if (delimiter != *ptr && isspace((int)*(const unsigned
char *)ptr)) {
- cnt++;
- break;
- }
- /* break is omitted intentionally */
default:
- cnt = 0;
+ last_chars[0] = last_chars[1];
+ last_chars[1] = *ptr;
break;
}
ptr += inc_len;
len -= inc_len;
}
quit_loop:
- return ptr - cnt;
+ switch (last_chars[1]) {
+ case '\n':
+ if (last_chars[0] == '\r') {
+ return ptr - 2;
+ }
+ /* break is omitted intentionally */
+ case '\r':
+ return ptr - 1;
+ }
+ return ptr;
}
/* {{{ proto array fgetcsv(resource fp [,int length [, string delimiter [, string
enclosure]]])
@@ -1853,7 +1859,7 @@
/* 1. Strip any leading space */
for (;;) {
- inc_len = (bptr < limit ? _php_mblen(bptr, limit - bptr): 0);
+ inc_len = (bptr < limit ? (*bptr == '\0' ? 1: _php_mblen(bptr,
limit - bptr)): 0);
switch (inc_len) {
case -2:
case -1:
@@ -1882,7 +1888,7 @@
/* 2A. handle enclosure delimited field */
for (;;) {
- inc_len = (bptr < limit ? _php_mblen(bptr, limit -
bptr): 0);
+ inc_len = (bptr < limit ? (*bptr == '\0' ? 1:
_php_mblen(bptr, limit - bptr)): 0);
switch (inc_len) {
case 0:
switch (state) {
@@ -2019,7 +2025,7 @@
break;
}
bptr += inc_len;
- inc_len = (bptr < limit ? _php_mblen(bptr, limit -
bptr): 0);
+ inc_len = (bptr < limit ? (*bptr == '\0' ? 1:
_php_mblen(bptr, limit - bptr)): 0);
}
quit_loop_3:
comp_end = tptr;
@@ -2033,7 +2039,7 @@
hunk_begin = bptr;
for (;;) {
- inc_len = (bptr < limit ? _php_mblen(bptr, limit -
bptr): 0);
+ inc_len = (bptr < limit ? (*bptr == '\0' ? 1:
_php_mblen(bptr, limit - bptr)): 0);
switch (inc_len) {
case 0:
goto quit_loop_4;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php