From c37bd23189d60a359a3fd97d1a9d8b47d3689045 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 25 Mar 2021 14:13:59 +0100 Subject: [PATCH 1/3] Remove zero size special case for copy_to_stream --- main/streams/streams.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/main/streams/streams.c b/main/streams/streams.c index 9bf744441269..430c3aa961bf 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1539,7 +1539,6 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size size_t haveread = 0; size_t towrite; size_t dummy; - php_stream_statbuf ssbuf; if (!len) { len = &dummy; @@ -1554,17 +1553,6 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size maxlen = 0; } - if (php_stream_stat(src, &ssbuf) == 0) { - if (ssbuf.sb.st_size == 0 -#ifdef S_ISREG - && S_ISREG(ssbuf.sb.st_mode) -#endif - ) { - *len = 0; - return SUCCESS; - } - } - if (php_stream_mmap_possible(src)) { char *p; From 5f63fd871ed6282c582c25509f2a8dadba314119 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 25 Mar 2021 18:44:15 +0100 Subject: [PATCH 2/3] Add test for copy from empty file --- .../file/stream_copy_to_stream_empty.phpt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ext/standard/tests/file/stream_copy_to_stream_empty.phpt diff --git a/ext/standard/tests/file/stream_copy_to_stream_empty.phpt b/ext/standard/tests/file/stream_copy_to_stream_empty.phpt new file mode 100644 index 000000000000..43e659a5a285 --- /dev/null +++ b/ext/standard/tests/file/stream_copy_to_stream_empty.phpt @@ -0,0 +1,19 @@ +--TEST-- +stream_copy_to_stream() from empty file +--FILE-- + +--CLEAN-- + +--EXPECT-- +int(0) From 7f973516c5f47272dc9319367bd1521e39f79b9e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 25 Mar 2021 19:05:31 +0100 Subject: [PATCH 3/3] Remove weird code --- main/streams/streams.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/main/streams/streams.c b/main/streams/streams.c index 430c3aa961bf..7df0dcce28d5 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1629,20 +1629,13 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size writeptr += didwrite; } - if (maxlen - haveread == 0) { + if (maxlen && maxlen == haveread) { break; } } *len = haveread; - - /* we've got at least 1 byte to read. - * less than 1 is an error */ - - if (haveread > 0 || src->eof) { - return SUCCESS; - } - return FAILURE; + return SUCCESS; } /* Returns the number of bytes moved.