cellog          Wed Apr 29 03:24:09 2009 UTC

  Modified files:              
    /php-src/ext/phar   phar.c phar_internal.h phar_object.c tar.c util.c 
                        zip.c 
  Log:
  MFPECL: fix PECL bug #16338, php_stream_copy_to_stream{,_ex}()
  
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.396&r2=1.397&diff_format=u
Index: php-src/ext/phar/phar.c
diff -u php-src/ext/phar/phar.c:1.396 php-src/ext/phar/phar.c:1.397
--- php-src/ext/phar/phar.c:1.396       Fri Feb 20 05:06:52 2009
+++ php-src/ext/phar/phar.c     Wed Apr 29 03:24:08 2009
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar.c,v 1.396 2009/02/20 05:06:52 cellog Exp $ */
+/* $Id: phar.c,v 1.397 2009/04/29 03:24:08 cellog Exp $ */
 
 #define PHAR_MAIN 1
 #include "phar_internal.h"
@@ -1635,7 +1635,7 @@
 
                                php_stream_filter_append(&temp->writefilters, 
filter);
 
-                               if (0 == php_stream_copy_to_stream(fp, temp, 
PHP_STREAM_COPY_ALL)) {
+                               if (SUCCESS != phar_stream_copy_to_stream(fp, 
temp, PHP_STREAM_COPY_ALL, NULL)) {
                                        if (err) {
                                                php_stream_close(temp);
                                                MAPPHAR_ALLOC_FAIL("unable to 
decompress gzipped phar archive \"%s\", ext/zlib is buggy in PHP versions older 
than 5.2.6")
@@ -1677,7 +1677,7 @@
 
                                php_stream_filter_append(&temp->writefilters, 
filter);
 
-                               if (0 == php_stream_copy_to_stream(fp, temp, 
PHP_STREAM_COPY_ALL)) {
+                               if (SUCCESS != phar_stream_copy_to_stream(fp, 
temp, PHP_STREAM_COPY_ALL, NULL)) {
                                        php_stream_close(temp);
                                        MAPPHAR_ALLOC_FAIL("unable to 
decompress bzipped phar archive \"%s\" to temporary file")
                                }
@@ -2661,7 +2661,7 @@
                size_t written;
 
                if (!user_stub && phar->halt_offset && oldfile && 
!phar->is_brandnew) {
-                       written = php_stream_copy_to_stream(oldfile, newfile, 
phar->halt_offset);
+                       phar_stream_copy_to_stream(oldfile, newfile, 
phar->halt_offset, &written);
                        newstub = NULL;
                } else {
                        /* this is either a brand new phar or a default stub 
overwrite */
@@ -2849,7 +2849,7 @@
                        return EOF;
                }
                php_stream_filter_append((&entry->cfp->writefilters), filter);
-               if (entry->uncompressed_filesize != 
php_stream_copy_to_stream(file, entry->cfp, entry->uncompressed_filesize)) {
+               if (SUCCESS != phar_stream_copy_to_stream(file, entry->cfp, 
entry->uncompressed_filesize, NULL)) {
                        if (closeoldfile) {
                                php_stream_close(oldfile);
                        }
@@ -3059,7 +3059,7 @@
                /* this will have changed for all files that have either 
changed compression or been modified */
                entry->offset = entry->offset_abs = offset;
                offset += entry->compressed_filesize;
-               wrote = php_stream_copy_to_stream(file, newfile, 
entry->compressed_filesize);
+               phar_stream_copy_to_stream(file, newfile, 
entry->compressed_filesize, &wrote);
 
                if (entry->compressed_filesize != wrote) {
                        if (closeoldfile) {
@@ -3207,7 +3207,7 @@
                        }
 
                        php_stream_filter_append(&phar->fp->writefilters, 
filter);
-                       php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                       phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                        php_stream_filter_flush(filter, 1);
                        php_stream_filter_remove(filter, 1 TSRMLS_CC);
                        php_stream_close(phar->fp);
@@ -3216,14 +3216,14 @@
                } else if (phar->flags & PHAR_FILE_COMPRESSED_BZ2) {
                        filter = php_stream_filter_create("bzip2.compress", 
NULL, php_stream_is_persistent(phar->fp) TSRMLS_CC);
                        php_stream_filter_append(&phar->fp->writefilters, 
filter);
-                       php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                       phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                        php_stream_filter_flush(filter, 1);
                        php_stream_filter_remove(filter, 1 TSRMLS_CC);
                        php_stream_close(phar->fp);
                        /* use the temp stream as our base */
                        phar->fp = newfile;
                } else {
-                       php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                       phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                        /* we could also reopen the file in "rb" mode but there 
is no need for that */
                        php_stream_close(newfile);
                }
@@ -3624,7 +3624,7 @@
        php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
        php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION);
        php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION);
-       php_info_print_table_row(2, "CVS revision", "$Revision: 1.396 $");
+       php_info_print_table_row(2, "CVS revision", "$Revision: 1.397 $");
        php_info_print_table_row(2, "Phar-based phar archives", "enabled");
        php_info_print_table_row(2, "Tar-based phar archives", "enabled");
        php_info_print_table_row(2, "ZIP-based phar archives", "enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar_internal.h?r1=1.121&r2=1.122&diff_format=u
Index: php-src/ext/phar/phar_internal.h
diff -u php-src/ext/phar/phar_internal.h:1.121 
php-src/ext/phar/phar_internal.h:1.122
--- php-src/ext/phar/phar_internal.h:1.121      Wed Dec 31 11:12:35 2008
+++ php-src/ext/phar/phar_internal.h    Wed Apr 29 03:24:08 2009
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar_internal.h,v 1.121 2008/12/31 11:12:35 sebastian Exp $ */
+/* $Id: phar_internal.h,v 1.122 2009/04/29 03:24:08 cellog Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -521,6 +521,23 @@
 # endif
 #endif
 
+#if PHP_VERSION_ID < 50209
+static inline size_t phar_stream_copy_to_stream(php_stream *src, php_stream 
*dest, size_t maxlen, size_t *len STREAMS_DC TSRMLS_DC)
+{
+       size_t ret = php_stream_copy_to_stream(src, dest, maxlen);
+       if (len) {
+               *len = ret;
+       }
+       if (ret) {
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+#else
+# define phar_stream_copy_to_stream(src, dest, maxlen, len)    
_php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC 
TSRMLS_CC)
+
+#endif
+
 #if PHP_VERSION_ID >= 60000
 typedef zstr phar_zstr;
 #define PHAR_STR(a, b) \
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar_object.c?r1=1.294&r2=1.295&diff_format=u
Index: php-src/ext/phar/phar_object.c
diff -u php-src/ext/phar/phar_object.c:1.294 
php-src/ext/phar/phar_object.c:1.295
--- php-src/ext/phar/phar_object.c:1.294        Sat Feb 21 02:37:33 2009
+++ php-src/ext/phar/phar_object.c      Wed Apr 29 03:24:09 2009
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: phar_object.c,v 1.294 2009/02/21 02:37:33 cellog Exp $ */
+/* $Id: phar_object.c,v 1.295 2009/04/29 03:24:09 cellog Exp $ */
 
 #include "phar_internal.h"
 #include "func_interceptors.h"
@@ -298,23 +298,31 @@
 
                                zend_try {
                                        zend_execute(new_op_array TSRMLS_CC);
-                               } zend_catch {
-                               } zend_end_try();
-                               destroy_op_array(new_op_array TSRMLS_CC);
-                               efree(new_op_array);
+                                       if (PHAR_G(cwd)) {
+                                               efree(PHAR_G(cwd));
+                                               PHAR_G(cwd) = NULL;
+                                               PHAR_G(cwd_len) = 0;
+                                       }
 
-                               if (PHAR_G(cwd)) {
-                                       efree(PHAR_G(cwd));
-                                       PHAR_G(cwd) = NULL;
-                                       PHAR_G(cwd_len) = 0;
-                               }
+                                       PHAR_G(cwd_init) = 0;
+                                       efree(name);
+                                       destroy_op_array(new_op_array 
TSRMLS_CC);
+                                       efree(new_op_array);
 
-                               PHAR_G(cwd_init) = 0;
-                               efree(name);
 
-                               if (EG(return_value_ptr_ptr) && 
*EG(return_value_ptr_ptr)) {
-                                       zval_ptr_dtor(EG(return_value_ptr_ptr));
-                               }
+                                       if (EG(return_value_ptr_ptr) && 
*EG(return_value_ptr_ptr)) {
+                                               
zval_ptr_dtor(EG(return_value_ptr_ptr));
+                                       }
+                               } zend_catch {
+                                       if (PHAR_G(cwd)) {
+                                               efree(PHAR_G(cwd));
+                                               PHAR_G(cwd) = NULL;
+                                               PHAR_G(cwd_len) = 0;
+                                       }
+
+                                       PHAR_G(cwd_init) = 0;
+                                       efree(name);
+                               } zend_end_try();
 
                                zend_bailout();
                        }
@@ -1414,7 +1422,7 @@
        uint str_key_len, base_len = p_obj->l, fname_len;
        phar_entry_data *data;
        php_stream *fp;
-       long contents_len;
+       size_t contents_len;
        char *fname, *error = NULL, *base = p_obj->b, *opened, *save = NULL, 
*temp = NULL;
        phar_zstr key;
        char *str_key;
@@ -1716,7 +1724,7 @@
                data->internal_file->fp_type = PHAR_UFP;
                data->internal_file->offset_abs = data->internal_file->offset = 
php_stream_tell(p_obj->fp);
                data->fp = NULL;
-               contents_len = php_stream_copy_to_stream(fp, p_obj->fp, 
PHP_STREAM_COPY_ALL);
+               phar_stream_copy_to_stream(fp, p_obj->fp, PHP_STREAM_COPY_ALL, 
&contents_len);
                data->internal_file->uncompressed_filesize = 
data->internal_file->compressed_filesize =
                        php_stream_tell(p_obj->fp) - 
data->internal_file->offset;
        }
@@ -1998,7 +2006,7 @@
                link = entry;
        }
 
-       if (link->uncompressed_filesize != 
php_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), fp, 
link->uncompressed_filesize)) {
+       if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 
TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
                zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 
TSRMLS_CC,
                        "Cannot convert phar archive \"%s\", unable to copy 
entry \"%s\" contents", entry->phar->fname, entry->filename);
                return FAILURE;
@@ -3560,7 +3568,7 @@
 static void phar_add_file(phar_archive_data **pphar, char *filename, int 
filename_len, char *cont_str, int cont_len, zval *zresource TSRMLS_DC)
 {
        char *error;
-       long contents_len;
+       size_t contents_len;
        phar_entry_data *data;
        php_stream *contents_file;
 
@@ -3594,7 +3602,7 @@
                                        
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Entry %s 
could not be written to", filename);
                                        return;
                                }
-                               contents_len = 
php_stream_copy_to_stream(contents_file, data->fp, PHP_STREAM_COPY_ALL);
+                               phar_stream_copy_to_stream(contents_file, 
data->fp, PHP_STREAM_COPY_ALL, &contents_len);
                        }
 
                        data->internal_file->compressed_filesize = 
data->internal_file->uncompressed_filesize = contents_len;
@@ -4151,7 +4159,7 @@
                return FAILURE;
        }
 
-       if (entry->uncompressed_filesize != 
php_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), fp, 
entry->uncompressed_filesize)) {
+       if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(entry, 0 
TSRMLS_CC), fp, entry->uncompressed_filesize, NULL)) {
                spprintf(error, 4096, "Cannot extract \"%s\" to \"%s\", copying 
contents failed", entry->filename, fullpath);
                efree(fullpath);
                php_stream_close(fp);
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tar.c?r1=1.66&r2=1.67&diff_format=u
Index: php-src/ext/phar/tar.c
diff -u php-src/ext/phar/tar.c:1.66 php-src/ext/phar/tar.c:1.67
--- php-src/ext/phar/tar.c:1.66 Sun Feb 15 18:52:11 2009
+++ php-src/ext/phar/tar.c      Wed Apr 29 03:24:09 2009
@@ -696,7 +696,7 @@
                        return ZEND_HASH_APPLY_STOP;
                }
 
-               if (entry->uncompressed_filesize != 
php_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), fp->new, 
entry->uncompressed_filesize)) {
+               if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(entry, 0 
TSRMLS_CC), fp->new, entry->uncompressed_filesize, NULL)) {
                        if (fp->error) {
                                spprintf(fp->error, 4096, "tar-based phar 
\"%s\" cannot be created, contents of file \"%s\" could not be written", 
entry->phar->fname, entry->filename);
                        }
@@ -1180,7 +1180,7 @@
 
                        if (!filter) {
                                /* copy contents uncompressed rather than lose 
them */
-                               php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                               phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                                php_stream_close(newfile);
                                if (error) {
                                        spprintf(error, 4096, "unable to 
compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 
have a buggy zlib", phar->fname);
@@ -1189,7 +1189,7 @@
                        }
 
                        php_stream_filter_append(&phar->fp->writefilters, 
filter);
-                       php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                       phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                        php_stream_filter_flush(filter, 1);
                        php_stream_filter_remove(filter, 1 TSRMLS_CC);
                        php_stream_close(phar->fp);
@@ -1200,14 +1200,14 @@
 
                        filter = php_stream_filter_create("bzip2.compress", 
NULL, php_stream_is_persistent(phar->fp) TSRMLS_CC);
                        php_stream_filter_append(&phar->fp->writefilters, 
filter);
-                       php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                       phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                        php_stream_filter_flush(filter, 1);
                        php_stream_filter_remove(filter, 1 TSRMLS_CC);
                        php_stream_close(phar->fp);
                        /* use the temp stream as our base */
                        phar->fp = newfile;
                } else {
-                       php_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL);
+                       phar_stream_copy_to_stream(newfile, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                        /* we could also reopen the file in "rb" mode but there 
is no need for that */
                        php_stream_close(newfile);
                }
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/util.c?r1=1.70&r2=1.71&diff_format=u
Index: php-src/ext/phar/util.c
diff -u php-src/ext/phar/util.c:1.70 php-src/ext/phar/util.c:1.71
--- php-src/ext/phar/util.c:1.70        Wed Dec 31 11:12:35 2008
+++ php-src/ext/phar/util.c     Wed Apr 29 03:24:09 2009
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: util.c,v 1.70 2008/12/31 11:12:35 sebastian Exp $ */
+/* $Id: util.c,v 1.71 2009/04/29 03:24:09 cellog Exp $ */
 
 #include "phar_internal.h"
 
@@ -893,7 +893,7 @@
                link = source;
        }
 
-       if (link->uncompressed_filesize != 
php_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), dest->fp, 
link->uncompressed_filesize)) {
+       if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 
TSRMLS_CC), dest->fp, link->uncompressed_filesize, NULL)) {
                php_stream_close(dest->fp);
                dest->fp_type = PHAR_FP;
                if (error) {
@@ -994,7 +994,7 @@
        php_stream_filter_append(&ufp->writefilters, filter);
        php_stream_seek(phar_get_entrypfp(entry TSRMLS_CC), 
phar_get_fp_offset(entry TSRMLS_CC), SEEK_SET);
 
-       if (php_stream_copy_to_stream(phar_get_entrypfp(entry TSRMLS_CC), ufp, 
entry->compressed_filesize) != entry->compressed_filesize) {
+       if (SUCCESS != phar_stream_copy_to_stream(phar_get_entrypfp(entry 
TSRMLS_CC), ufp, entry->compressed_filesize, NULL)) {
                spprintf(error, 4096, "phar error: internal corruption of phar 
\"%s\" (actual filesize mismatch on file \"%s\")", phar->fname, 
entry->filename);
                php_stream_filter_remove(filter, 1 TSRMLS_CC);
                return FAILURE;
@@ -1131,7 +1131,7 @@
                link = entry;
        }
 
-       if (link->uncompressed_filesize != 
php_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), fp, 
link->uncompressed_filesize)) {
+       if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 
TSRMLS_CC), fp, link->uncompressed_filesize, NULL)) {
                if (error) {
                        spprintf(error, 4096, "phar error: cannot separate 
entry file \"%s\" contents in phar archive \"%s\" for write access", 
entry->filename, entry->phar->fname);
                }
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/zip.c?r1=1.66&r2=1.67&diff_format=u
Index: php-src/ext/phar/zip.c
diff -u php-src/ext/phar/zip.c:1.66 php-src/ext/phar/zip.c:1.67
--- php-src/ext/phar/zip.c:1.66 Sun Mar  1 06:58:23 2009
+++ php-src/ext/phar/zip.c      Wed Apr 29 03:24:09 2009
@@ -833,7 +833,7 @@
 
                php_stream_filter_append((&entry->cfp->writefilters), filter);
 
-               if (entry->uncompressed_filesize != 
php_stream_copy_to_stream(efp, entry->cfp, entry->uncompressed_filesize)) {
+               if (SUCCESS != phar_stream_copy_to_stream(efp, entry->cfp, 
entry->uncompressed_filesize, NULL)) {
                        spprintf(p->error, 0, "unable to copy compressed file 
contents of file \"%s\" while creating new phar \"%s\"", entry->filename, 
entry->phar->fname);
                        return ZEND_HASH_APPLY_STOP;
                }
@@ -937,7 +937,7 @@
 
        if (!not_really_modified && entry->is_modified) {
                if (entry->cfp) {
-                       if (entry->compressed_filesize != 
php_stream_copy_to_stream(entry->cfp, p->filefp, entry->compressed_filesize)) {
+                       if (SUCCESS != phar_stream_copy_to_stream(entry->cfp, 
p->filefp, entry->compressed_filesize, NULL)) {
                                spprintf(p->error, 0, "unable to write 
compressed contents of file \"%s\" in zip-based phar \"%s\"", entry->filename, 
entry->phar->fname);
                                return ZEND_HASH_APPLY_STOP;
                        }
@@ -951,7 +951,7 @@
 
                        phar_seek_efp(entry, 0, SEEK_SET, 0, 0 TSRMLS_CC);
 
-                       if (entry->uncompressed_filesize != 
php_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), p->filefp, 
entry->uncompressed_filesize)) {
+                       if (SUCCESS != 
phar_stream_copy_to_stream(phar_get_efp(entry, 0 TSRMLS_CC), p->filefp, 
entry->uncompressed_filesize, NULL)) {
                                spprintf(p->error, 0, "unable to write contents 
of file \"%s\" in zip-based phar \"%s\"", entry->filename, entry->phar->fname);
                                return ZEND_HASH_APPLY_STOP;
                        }
@@ -977,7 +977,7 @@
                        }
                }
 
-               if (!entry->is_dir && entry->compressed_filesize && 
entry->compressed_filesize != php_stream_copy_to_stream(p->old, p->filefp, 
entry->compressed_filesize)) {
+               if (!entry->is_dir && entry->compressed_filesize && SUCCESS != 
phar_stream_copy_to_stream(p->old, p->filefp, entry->compressed_filesize, 
NULL)) {
                        spprintf(p->error, 0, "unable to copy contents of file 
\"%s\" while creating zip-based phar \"%s\"", entry->filename, 
entry->phar->fname);
                        return ZEND_HASH_APPLY_STOP;
                }
@@ -1241,11 +1241,15 @@
        PHAR_SET_32(eocd.cdir_offset, cdir_offset);
        php_stream_seek(pass.centralfp, 0, SEEK_SET);
 
-       if (cdir_size != php_stream_copy_to_stream(pass.centralfp, pass.filefp, 
PHP_STREAM_COPY_ALL)) {
-               if (error) {
-                       spprintf(error, 4096, "phar zip flush of \"%s\" failed: 
unable to write central-directory", phar->fname);
+       {
+               size_t len;
+               int ret = phar_stream_copy_to_stream(pass.centralfp, 
pass.filefp, PHP_STREAM_COPY_ALL, &len);
+               if (SUCCESS != ret || len != cdir_size) {
+                       if (error) {
+                               spprintf(error, 4096, "phar zip flush of \"%s\" 
failed: unable to write central-directory", phar->fname);
+                       }
+                       goto temperror;
                }
-               goto temperror;
        }
 
        php_stream_close(pass.centralfp);
@@ -1312,7 +1316,7 @@
                        return EOF;
                }
                php_stream_rewind(pass.filefp);
-               php_stream_copy_to_stream(pass.filefp, phar->fp, 
PHP_STREAM_COPY_ALL);
+               phar_stream_copy_to_stream(pass.filefp, phar->fp, 
PHP_STREAM_COPY_ALL, NULL);
                /* we could also reopen the file in "rb" mode but there is no 
need for that */
                php_stream_close(pass.filefp);
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to