From efa9b7e20b6299c27b5dfdd453e43e433dbfd7c0 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Wed, 22 Nov 2006 12:59:49 +0000 Subject: [PATCH] - MFH: #39538, fgetcsv can't handle starting newlines and trailing odd number of backslashes (David Soria Parra, Pierre) --- NEWS | 2 ++ ext/standard/file.c | 8 ++++-- ext/standard/tests/file/bug39538.phpt | 40 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 ext/standard/tests/file/bug39538.phpt diff --git a/NEWS b/NEWS index 210a08d0318..71a2f4e4c27 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,8 @@ PHP NEWS - Fixed wrong signature initialization in imagepng (Takeshi Abe) - Added optimization for imageline with horizontal and vertial lines (Pierre) - Fixed bug #39576 (array_walk() doesn't separate userdata zval). (Tony) +- Fixed bug #39538 (fgetcsv can't handle starting newlines and trailing odd + number of backslashes). (David Soria Parra, Pierre) - Fixed bug #39454 (Returning a SOAP array segfaults PHP). (Dmitry) - Fixed bug #39445 (Calling debug_backtrace() in the __toString() function produces a crash). (Dmitry) diff --git a/ext/standard/file.c b/ext/standard/file.c index 9cf583a7367..83fd20839d9 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2171,9 +2171,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, /* {{{ */ size_t new_len; char *new_temp; - memcpy(tptr, hunk_begin, bptr - hunk_begin); - tptr += (bptr - hunk_begin); - hunk_begin = bptr; + if (hunk_begin != line_end) { + memcpy(tptr, hunk_begin, bptr - hunk_begin); + tptr += (bptr - hunk_begin); + hunk_begin = bptr; + } /* add the embedded line end to the field */ memcpy(tptr, line_end, line_end_len); diff --git a/ext/standard/tests/file/bug39538.phpt b/ext/standard/tests/file/bug39538.phpt new file mode 100644 index 00000000000..16f15234fcf --- /dev/null +++ b/ext/standard/tests/file/bug39538.phpt @@ -0,0 +1,40 @@ +--TEST-- +bug 39538 +--FILE-- + +this is an test + [1] => next data + [2] => p +arsed +) +Array +( + [0] => +this is an test + [1] => next data + [2] => p +arsed +) +Array +( + [0] => + +this is an test + [1] => next data + [2] => p + +arsed +)