com php-src: Fixed Bug #64565 copy doesn't report failure on partial copy: main/streams/streams.c
| From: | Remi Collet | Date: | Tue, 02 Apr 2013 14:18:26 +0000 |
| Subject: | com php-src: Fixed Bug #64565 copy doesn't report failure on partial copy: main/streams/streams.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-71826@lists.php.net to get a copy of this message | ||
Commit: 6b4148bc9705d2668dd8589009215a8eb3076f31
Author: Remi Collet <remi@php.net> Tue, 2 Apr 2013 16:18:26 +0200
Parents: 7b07d05917d9ff40a70bd6ecffca840e2458ea86
Branches: PHP-5.4 PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6b4148bc9705d2668dd8589009215a8eb3076f31
Log:
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.
Bugs:
https://bugs.php.net/64565
Changed paths:
M main/streams/streams.c
Diff:
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 47d86b5..39e231d 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;