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 0000000000000..43e659a5a2850 --- /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) diff --git a/main/streams/streams.c b/main/streams/streams.c index 9bf7444412699..7df0dcce28d55 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; @@ -1641,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.