lbarnaud Sun Apr 19 14:44:10 2009 UTC Added files: (Branch: PHP_5_2) /php-src/ext/standard/tests/streams bug47997.phpt
Modified files: /php-src NEWS /php-src/ext/standard file.c streamsfuncs.c /php-src/main php_streams.h /php-src/main/streams cast.c streams.c Log: MFB5.3: Fixed bug #47997 (stream_copy_to_stream returns 1 on empty streams)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1471&r2=1.2027.2.547.2.1472&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.1471 php-src/NEWS:1.2027.2.547.2.1472 --- php-src/NEWS:1.2027.2.547.2.1471 Thu Apr 16 13:53:24 2009 +++ php-src/NEWS Sun Apr 19 14:44:09 2009 @@ -10,6 +10,7 @@ - Fixed memory leak in ob_get_clean/ob_get_flush. (Christian) - Fixed segfault on invalid session.save_path. (Hannes) +- Fixed bug #47997 (stream_copy_to_stream returns 1 on empty streams). (Arnaud) - Fixed bug #47981 (error handler not called regardless). (Hannes) - Fixed bug #47969 (ezmlm_hash() returns different values depend on OS). (Ilia) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.38&r2=1.409.2.6.2.39&diff_format=u Index: php-src/ext/standard/file.c diff -u php-src/ext/standard/file.c:1.409.2.6.2.38 php-src/ext/standard/file.c:1.409.2.6.2.39 --- php-src/ext/standard/file.c:1.409.2.6.2.38 Wed Dec 31 11:17:44 2008 +++ php-src/ext/standard/file.c Sun Apr 19 14:44:09 2009 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.409.2.6.2.38 2008/12/31 11:17:44 sebastian Exp $ */ +/* $Id: file.c,v 1.409.2.6.2.39 2009/04/19 14:44:09 lbarnaud Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -630,7 +630,10 @@ switch (Z_TYPE_P(data)) { case IS_RESOURCE: - numbytes = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL); + numbytes = (int) php_stream_copy_to_stream_ex(srcstream, stream, PHP_STREAM_COPY_ALL); + if ((size_t)numbytes == PHP_STREAM_FAILURE) { + numbytes = -1; + } break; case IS_NULL: case IS_LONG: @@ -1836,7 +1839,7 @@ deststream = php_stream_open_wrapper(dest, "wb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (srcstream && deststream) { - ret = php_stream_copy_to_stream(srcstream, deststream, PHP_STREAM_COPY_ALL) == 0 ? FAILURE : SUCCESS; + ret = php_stream_copy_to_stream_ex(srcstream, deststream, PHP_STREAM_COPY_ALL) == PHP_STREAM_FAILURE ? FAILURE : SUCCESS; } if (srcstream) { php_stream_close(srcstream); http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.58.2.6.2.31&r2=1.58.2.6.2.32&diff_format=u Index: php-src/ext/standard/streamsfuncs.c diff -u php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.31 php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.32 --- php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.31 Thu Jan 8 17:03:42 2009 +++ php-src/ext/standard/streamsfuncs.c Sun Apr 19 14:44:09 2009 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streamsfuncs.c,v 1.58.2.6.2.31 2009/01/08 17:03:42 lbarnaud Exp $ */ +/* $Id: streamsfuncs.c,v 1.58.2.6.2.32 2009/04/19 14:44:09 lbarnaud Exp $ */ #include "php.h" #include "php_globals.h" @@ -437,6 +437,7 @@ php_stream *src, *dest; zval *zsrc, *zdest; long maxlen = PHP_STREAM_COPY_ALL, pos = 0; + size_t ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|ll", &zsrc, &zdest, &maxlen, &pos) == FAILURE) { RETURN_FALSE; @@ -450,7 +451,12 @@ RETURN_FALSE; } - RETURN_LONG(php_stream_copy_to_stream(src, dest, maxlen)); + ret = php_stream_copy_to_stream_ex(src, dest, maxlen); + + if (ret == PHP_STREAM_FAILURE) { + RETURN_FALSE; + } + RETURN_LONG(ret); } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/main/php_streams.h?r1=1.103.2.1.2.9&r2=1.103.2.1.2.10&diff_format=u Index: php-src/main/php_streams.h diff -u php-src/main/php_streams.h:1.103.2.1.2.9 php-src/main/php_streams.h:1.103.2.1.2.10 --- php-src/main/php_streams.h:1.103.2.1.2.9 Wed Dec 31 11:17:47 2008 +++ php-src/main/php_streams.h Sun Apr 19 14:44:09 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams.h,v 1.103.2.1.2.9 2008/12/31 11:17:47 sebastian Exp $ */ +/* $Id: php_streams.h,v 1.103.2.1.2.10 2009/04/19 14:44:09 lbarnaud Exp $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -416,9 +416,13 @@ * Uses mmap if the src is a plain file and at offset 0 */ #define PHP_STREAM_COPY_ALL ((size_t)-1) +#define PHP_STREAM_FAILURE ((size_t)-1) + BEGIN_EXTERN_C() PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC); #define php_stream_copy_to_stream(src, dest, maxlen) _php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC) +PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC); +#define php_stream_copy_to_stream_ex(src, dest, maxlen) _php_stream_copy_to_stream_ex((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC) /* read all data from stream and put into a buffer. Caller must free buffer when done. http://cvs.php.net/viewvc.cgi/php-src/main/streams/cast.c?r1=1.12.2.1.2.3&r2=1.12.2.1.2.4&diff_format=u Index: php-src/main/streams/cast.c diff -u php-src/main/streams/cast.c:1.12.2.1.2.3 php-src/main/streams/cast.c:1.12.2.1.2.4 --- php-src/main/streams/cast.c:1.12.2.1.2.3 Wed Dec 31 11:17:48 2008 +++ php-src/main/streams/cast.c Sun Apr 19 14:44:09 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cast.c,v 1.12.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */ +/* $Id: cast.c,v 1.12.2.1.2.4 2009/04/19 14:44:09 lbarnaud Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -214,9 +214,9 @@ newstream = php_stream_fopen_tmpfile(); if (newstream) { - size_t copied = php_stream_copy_to_stream(stream, newstream, PHP_STREAM_COPY_ALL); + size_t copied = php_stream_copy_to_stream_ex(stream, newstream, PHP_STREAM_COPY_ALL); - if (copied == 0) { + if (copied == PHP_STREAM_FAILURE) { php_stream_close(newstream); } else { int retcode = php_stream_cast(newstream, castas | flags, ret, show_err); @@ -327,7 +327,7 @@ if (*newstream == NULL) return PHP_STREAM_FAILED; - if (php_stream_copy_to_stream(origstream, *newstream, PHP_STREAM_COPY_ALL) == 0) { + if (php_stream_copy_to_stream_ex(origstream, *newstream, PHP_STREAM_COPY_ALL) == PHP_STREAM_FAILURE) { php_stream_close(*newstream); *newstream = NULL; return PHP_STREAM_CRITICAL; http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.82.2.6.2.34&r2=1.82.2.6.2.35&diff_format=u Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.82.2.6.2.34 php-src/main/streams/streams.c:1.82.2.6.2.35 --- php-src/main/streams/streams.c:1.82.2.6.2.34 Thu Mar 19 17:56:00 2009 +++ php-src/main/streams/streams.c Sun Apr 19 14:44:09 2009 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.82.2.6.2.34 2009/03/19 17:56:00 lbarnaud Exp $ */ +/* $Id: streams.c,v 1.82.2.6.2.35 2009/04/19 14:44:09 lbarnaud Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1288,7 +1288,8 @@ return len; } -PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC) +/* Returns the number of bytes moved, or PHP_STREAM_FAILURE on failure. */ +PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC) { char buf[CHUNK_SIZE]; size_t readchunk; @@ -1305,8 +1306,6 @@ } if (php_stream_stat(src, &ssbuf) == 0) { - /* in the event that the source file is 0 bytes, return 1 to indicate success - * because opening the file to write had already created a copy */ if (ssbuf.sb.st_size == 0 #ifdef S_ISFIFO && !S_ISFIFO(ssbuf.sb.st_mode) @@ -1315,7 +1314,7 @@ && !S_ISCHR(ssbuf.sb.st_mode) #endif ) { - return 1; + return 0; } } @@ -1329,8 +1328,14 @@ mapped = php_stream_write(dest, p, mapped); php_stream_mmap_unmap(src); + + /* we've got at least 1 byte to read. + * less than 1 is an error */ - return mapped; + if (mapped > 0) { + return mapped; + } + return PHP_STREAM_FAILURE; } } @@ -1354,22 +1359,40 @@ while(towrite) { didwrite = php_stream_write(dest, writeptr, towrite); if (didwrite == 0) { - return 0; /* error */ + return PHP_STREAM_FAILURE; } towrite -= didwrite; writeptr += didwrite; } } else { - return haveread; + break; } if (maxlen - haveread == 0) { break; } } - return haveread; + /* we've got at least 1 byte to read. + * less than 1 is an error */ + + if (haveread > 0) { + return haveread; + } + return PHP_STREAM_FAILURE; +} + +/* Returns the number of bytes moved. + * Returns 1 when source len is 0. + * Deprecated in favor of php_stream_copy_to_stream_ex() */ +PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC) +{ + size_t ret = _php_stream_copy_to_stream_ex(src, dest, maxlen STREAMS_REL_CC TSRMLS_CC); + if (ret == 0 && maxlen != 0) { + return 1; + } + return ret; } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/streams/bug47997.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/streams/bug47997.phpt +++ php-src/ext/standard/tests/streams/bug47997.phpt
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php