diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index ff0b54798fa..478132fd403 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -91,9 +91,9 @@ static inline void strip_header(char *header_bag, char *lc_header_bag, ) { char *header_start = header_bag + (lc_header_start - lc_header_bag); char *lc_eol = strchr(lc_header_start, '\n'); - char *eol = header_start + (lc_eol - lc_header_start); if (lc_eol) { + char *eol = header_start + (lc_eol - lc_header_start); size_t eollen = strlen(lc_eol); memmove(lc_header_start, lc_eol+1, eollen); diff --git a/ext/standard/tests/streams/bug78506.phpt b/ext/standard/tests/streams/bug78506.phpt new file mode 100644 index 00000000000..869fa2a8ff3 --- /dev/null +++ b/ext/standard/tests/streams/bug78506.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #78506: Error in a php_user_filter::filter() is not reported +--FILE-- + +--EXPECT-- +bool(false) diff --git a/main/streams/streams.c b/main/streams/streams.c index 566cdcde080..aef1ebe7626 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1586,33 +1586,31 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size while(1) { size_t readchunk = sizeof(buf); ssize_t didread; + char *writeptr; if (maxlen && (maxlen - haveread) < readchunk) { readchunk = maxlen - haveread; } didread = php_stream_read(src, buf, readchunk); + if (didread <= 0) { + *len = haveread; + return didread < 0 ? FAILURE : SUCCESS; + } - if (didread > 0) { - /* extra paranoid */ - char *writeptr; + towrite = didread; + writeptr = buf; + haveread += didread; - towrite = didread; - writeptr = buf; - haveread += didread; - - while (towrite) { - ssize_t didwrite = php_stream_write(dest, writeptr, towrite); - if (didwrite <= 0) { - *len = haveread - (didread - towrite); - return FAILURE; - } - - towrite -= didwrite; - writeptr += didwrite; + while (towrite) { + ssize_t didwrite = php_stream_write(dest, writeptr, towrite); + if (didwrite <= 0) { + *len = haveread - (didread - towrite); + return FAILURE; } - } else { - break; + + towrite -= didwrite; + writeptr += didwrite; } if (maxlen - haveread == 0) {