From f834ad3142ba6cb07c3efba9c4a253d24a447026 Mon Sep 17 00:00:00 2001 From: Aliaksandr Bystry Date: Thu, 30 Sep 2021 09:12:45 +0200 Subject: [PATCH 1/2] Fix #66588: SplFileObject::fgetcsv incorrectly returns a row on premature EOF. This bug is about the different behavior with and without trailing newline. --- ext/standard/file.c | 6 +----- ext/standard/tests/file/bug66588.phpt | 31 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 ext/standard/tests/file/bug66588.phpt diff --git a/ext/standard/file.c b/ext/standard/file.c index 3bd3421603f78..d29a72d592918 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2177,11 +2177,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int * assign all the data from the start of * the enclosure to end of data to the * last element */ - if ((size_t)temp_len > (size_t)(limit - buf)) { - goto quit_loop_2; - } - zend_array_destroy(Z_ARR_P(return_value)); - RETVAL_FALSE; + goto quit_loop_2; goto out; } temp_len += new_len; diff --git a/ext/standard/tests/file/bug66588.phpt b/ext/standard/tests/file/bug66588.phpt new file mode 100644 index 0000000000000..c01340a4f70c3 --- /dev/null +++ b/ext/standard/tests/file/bug66588.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #66588 SplFileObject::fgetcsv incorrectly returns a row on premature EOF +--DESCRIPTION-- +This bug is about the different behavior with and without trailing newline both should behave the same, +and neither should return FALSE. +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + string(4) ",bar" +} +array(1) { + [0]=> + string(5) ",bar +" +} \ No newline at end of file From 9ec66830c66eeb4a4776e2c83997bd7629be731d Mon Sep 17 00:00:00 2001 From: Aliaksandr Bystry Date: Thu, 30 Sep 2021 09:14:48 +0200 Subject: [PATCH 2/2] Add new line at the end of test file. --- ext/standard/tests/file/bug66588.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/tests/file/bug66588.phpt b/ext/standard/tests/file/bug66588.phpt index c01340a4f70c3..697a3e67329e1 100644 --- a/ext/standard/tests/file/bug66588.phpt +++ b/ext/standard/tests/file/bug66588.phpt @@ -28,4 +28,4 @@ array(1) { [0]=> string(5) ",bar " -} \ No newline at end of file +}