summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
diff options
context:
space:
mode:
authorRemi Collet <remi@php.net>2013-04-02 16:18:26 +0200
committerRemi Collet <remi@php.net>2013-04-02 16:18:26 +0200
commit6b4148bc9705d2668dd8589009215a8eb3076f31 (patch)
tree5d9418b5a1eb05774d60ef76e652774b3ac4ca1d /main/streams/streams.c
parent7b07d05917d9ff40a70bd6ecffca840e2458ea86 (diff)
downloadphp-git-6b4148bc9705d2668dd8589009215a8eb3076f31.tar.gz
Fixed Bug #64565 copy doesn't report failure on partial copy
_php_stream_copy_to_stream_ex, when mmap is possible, doesn't check if actually written bytes match read bytes. Fix this (paranoid check) to be consistent with non mmap mode Seems hard to add a unit test, as this rely on a full filesystem.
Diffstat (limited to 'main/streams/streams.c')
-rw-r--r--main/streams/streams.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 47d86b586e..39e231dbb6 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1494,7 +1494,7 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
char buf[CHUNK_SIZE];
size_t readchunk;
size_t haveread = 0;
- size_t didread;
+ size_t didread, didwrite, towrite;
size_t dummy;
php_stream_statbuf ssbuf;
@@ -1529,16 +1529,16 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
if (p) {
- mapped = php_stream_write(dest, p, mapped);
+ didwrite = php_stream_write(dest, p, mapped);
php_stream_mmap_unmap_ex(src, mapped);
- *len = mapped;
+ *len = didwrite;
/* we've got at least 1 byte to read.
* less than 1 is an error */
- if (mapped > 0) {
+ if (mapped == didwrite) {
return SUCCESS;
}
return FAILURE;
@@ -1556,7 +1556,6 @@ PHPAPI int _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size
if (didread) {
/* extra paranoid */
- size_t didwrite, towrite;
char *writeptr;
towrite = didread;