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")
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")
}
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 */
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);
}
/* 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) {
}
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);
} 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);
}
# 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) \
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();
}
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;
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;
}
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;
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;
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;
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);
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);
}
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);
}
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);
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);
}
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) {
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;
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);
}
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;
}
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;
}
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;
}
}
}
- 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;
}
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);
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);
}