]> granicus.if.org Git - php/commitdiff
Fixed Bug #64565 copy doesn't report failure on partial copy
authorRemi Collet <remi@php.net>
Tue, 2 Apr 2013 14:18:26 +0000 (16:18 +0200)
committerRemi Collet <remi@php.net>
Tue, 2 Apr 2013 14:18:26 +0000 (16:18 +0200)
_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.

main/streams/streams.c

index 47d86b586e0bad77643a6f10206a8221649990b1..39e231dbb638d4aa865116109ecdf0edf06e50cf 100644 (file)
@@ -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;