--- embedaddon/php/ext/phar/zip.c 2012/02/21 23:47:59 1.1.1.1 +++ embedaddon/php/ext/phar/zip.c 2013/07/22 01:31:59 1.1.1.2 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | ZIP archive support for Phar | +----------------------------------------------------------------------+ - | Copyright (c) 2007-2012 The PHP Group | + | Copyright (c) 2007-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -603,11 +603,7 @@ foundit: php_stream_filter_append(&fp->readfilters, filter); -#if PHP_MAJOR_VERSION >= 6 - if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, (void **) &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { -#else if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { -#endif pefree(entry.filename, entry.is_persistent); #if PHP_VERSION_ID < 50207 PHAR_ZIP_FAIL("unable to read in alias, truncated (PHP 5.2.7 and newer has a potential fix for this problem)"); @@ -628,11 +624,7 @@ foundit: php_stream_filter_append(&fp->readfilters, filter); -#if PHP_MAJOR_VERSION >= 6 - if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, (void **) &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { -#else if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { -#endif pefree(entry.filename, entry.is_persistent); #if PHP_VERSION_ID < 50207 PHAR_ZIP_FAIL("unable to read in alias, truncated (PHP 5.2.7 and newer has a potential fix for this problem)"); @@ -643,11 +635,7 @@ foundit: php_stream_filter_flush(filter, 1); php_stream_filter_remove(filter, 1 TSRMLS_CC); } else { -#if PHP_MAJOR_VERSION >= 6 - if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, (void **) &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { -#else if (!(entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)) || !actual_alias) { -#endif pefree(entry.filename, entry.is_persistent); PHAR_ZIP_FAIL("unable to read in alias, truncated"); } @@ -949,10 +937,11 @@ is_compressed: PHAR_SET_32(local.uncompsize, entry->uncompressed_filesize); PHAR_SET_32(central.compsize, entry->compressed_filesize); PHAR_SET_32(local.compsize, entry->compressed_filesize); - - if (-1 == php_stream_seek(p->old, entry->offset_abs, SEEK_SET)) { - spprintf(p->error, 0, "unable to seek to start of file \"%s\" while creating zip-based phar \"%s\"", entry->filename, entry->phar->fname); - return ZEND_HASH_APPLY_STOP; + if (p->old) { + if (-1 == php_stream_seek(p->old, entry->offset_abs, SEEK_SET)) { + spprintf(p->error, 0, "unable to seek to start of file \"%s\" while creating zip-based phar \"%s\"", entry->filename, entry->phar->fname); + return ZEND_HASH_APPLY_STOP; + } } } not_compressed: @@ -1107,6 +1096,10 @@ static int phar_zip_applysignature(phar_archive_data * off_t tell, st; newfile = php_stream_fopen_tmpfile(); + if (newfile == NULL) { + spprintf(pass->error, 0, "phar error: unable to create temporary file for the signature file"); + return FAILURE; + } st = tell = php_stream_tell(pass->filefp); /* copy the local files, central directory, and the zip comment to generate the hash */ php_stream_seek(pass->filefp, 0, SEEK_SET); @@ -1134,6 +1127,10 @@ static int phar_zip_applysignature(phar_archive_data * entry.fp = php_stream_fopen_tmpfile(); entry.fp_type = PHAR_MOD; entry.is_modified = 1; + if (entry.fp == NULL) { + spprintf(pass->error, 0, "phar error: unable to create temporary file for signature"); + return FAILURE; + } PHAR_SET_32(sigbuf, phar->sig_flags); PHAR_SET_32(sigbuf + 4, signature_length); @@ -1204,7 +1201,10 @@ int phar_zip_flush(phar_archive_data *phar, char *user /* set alias */ if (!phar->is_temporary_alias && phar->alias_len) { entry.fp = php_stream_fopen_tmpfile(); - + if (entry.fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return EOF; + } if (phar->alias_len != (int)php_stream_write(entry.fp, phar->alias, phar->alias_len)) { if (error) { spprintf(error, 0, "unable to set alias in zip-based phar \"%s\"", phar->fname); @@ -1252,11 +1252,7 @@ int phar_zip_flush(phar_archive_data *phar, char *user user_stub = 0; -#if PHP_MAJOR_VERSION >= 6 - if (!(len = php_stream_copy_to_mem(stubfile, (void **) &user_stub, len, 0)) || !user_stub) { -#else if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) { -#endif if (error) { spprintf(error, 0, "unable to read resource to copy stub to new zip-based phar \"%s\"", phar->fname); } @@ -1283,6 +1279,10 @@ int phar_zip_flush(phar_archive_data *phar, char *user len = pos - user_stub + 18; entry.fp = php_stream_fopen_tmpfile(); + if (entry.fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return EOF; + } entry.uncompressed_filesize = len + 5; if ((size_t)len != php_stream_write(entry.fp, user_stub, len) @@ -1316,7 +1316,10 @@ int phar_zip_flush(phar_archive_data *phar, char *user } else { /* Either this is a brand new phar (add the stub), or the default stub is required (overwrite the stub) */ entry.fp = php_stream_fopen_tmpfile(); - + if (entry.fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return EOF; + } if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { php_stream_close(entry.fp); if (error) {