diff options
author | Ondřej Surý <ondrej@sury.org> | 2013-10-27 20:38:12 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2013-10-27 20:38:12 +0100 |
commit | 749e5ad39dbac3f4f62be438367f8cdf90056815 (patch) | |
tree | ad0677df3bf44a6761380686e400ffd878585288 /ext/phar | |
parent | 4ed39205864f58ba7c368e4ae1362d8214469fd9 (diff) | |
download | php-749e5ad39dbac3f4f62be438367f8cdf90056815.tar.gz |
New upstream version 5.4.21upstream/5.4.21
Diffstat (limited to 'ext/phar')
-rw-r--r-- | ext/phar/Makefile.frag | 4 | ||||
-rw-r--r-- | ext/phar/config.m4 | 2 | ||||
-rw-r--r-- | ext/phar/func_interceptors.c | 2 | ||||
-rw-r--r-- | ext/phar/phar.1.in | 523 | ||||
-rw-r--r-- | ext/phar/phar.c | 23 | ||||
-rw-r--r-- | ext/phar/phar.phar.1.in | 1 | ||||
-rw-r--r-- | ext/phar/phar_object.c | 12 | ||||
-rw-r--r-- | ext/phar/tar.c | 25 | ||||
-rw-r--r-- | ext/phar/tests/bug65028.phpt | 156 | ||||
-rw-r--r-- | ext/phar/tests/files/openssl.cnf | 2 | ||||
-rw-r--r-- | ext/phar/util.c | 8 | ||||
-rw-r--r-- | ext/phar/zip.c | 31 |
12 files changed, 776 insertions, 13 deletions
diff --git a/ext/phar/Makefile.frag b/ext/phar/Makefile.frag index b1c820f27..ed6de9fd6 100644 --- a/ext/phar/Makefile.frag +++ b/ext/phar/Makefile.frag @@ -40,3 +40,7 @@ install-pharcmd: pharcmd $(INSTALL) $(builddir)/phar.phar $(INSTALL_ROOT)$(bindir) -@rm -f $(INSTALL_ROOT)$(bindir)/phar $(LN_S) -f $(bindir)/phar.phar $(INSTALL_ROOT)$(bindir)/phar + @$(mkinstalldirs) $(INSTALL_ROOT)$(mandir)/man1 + @$(INSTALL_DATA) $(builddir)/phar.1 $(INSTALL_ROOT)$(mandir)/man1/phar.1 + @$(INSTALL_DATA) $(builddir)/phar.phar.1 $(INSTALL_ROOT)$(mandir)/man1/phar.phar.1 + diff --git a/ext/phar/config.m4 b/ext/phar/config.m4 index 2ac7f3dd8..d424060f2 100644 --- a/ext/phar/config.m4 +++ b/ext/phar/config.m4 @@ -27,4 +27,6 @@ if test "$PHP_PHAR" != "no"; then PHP_ADD_EXTENSION_DEP(phar, hash, true) PHP_ADD_EXTENSION_DEP(phar, spl, true) PHP_ADD_MAKEFILE_FRAGMENT + + PHP_OUTPUT(ext/phar/phar.1 ext/phar/phar.phar.1) fi diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index 65193726d..00cb92ff1 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -733,7 +733,7 @@ notfound: PHAR_G(cwd_len) = save_len; efree(entry); efree(arch); - /* Error Occured */ + /* Error Occurred */ if (!IS_EXISTS_CHECK(type)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename); } diff --git a/ext/phar/phar.1.in b/ext/phar/phar.1.in new file mode 100644 index 000000000..259a2bae8 --- /dev/null +++ b/ext/phar/phar.1.in @@ -0,0 +1,523 @@ +.TH PHAR 1 "2013" "The PHP Group" "User Commands" +.SH NAME +phar, phar.phar \- PHAR (PHP archive) command line tool +.SH SYNOPSIS +.B phar +<command> [options] ... +.LP +.SH DESCRIPTION +The \fBPHAR\fP file format provides a way to put entire PHP applications into a single +file called a "phar" (PHP Archive) for easy distribution and installation. +.P +With the \fBphar\fP command you can create, update or extract PHP archives. +.P +Commands: +add compress delete extract help help-list info list meta-del +meta-get meta-set pack sign stub-get stub-set tree version + +.SH add command +Add entries to a PHAR package. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.TP +.PD +.B ... +Any number of input files and directories. If -i is in +use then ONLY files and matching the given regular +expression are being packed. If -x is given then files +matching that regular expression are NOT being packed. +.P +Optional arguments: +.TP 15 +.PD +.B \-a \fIalias\fP +Provide an \fIalias\fP name for the phar file. +.TP +.PD +.B \-c \fIalgo\fP +Compression algorithm (see +.SM +.B COMPRESSION +) +.TP +.PD +.B \-i \fIregex\fP +Specifies a regular expression for input files. +.TP +.PD +.B \-l \fIlevel\fP +Number of preceding subdirectories to strip from file entries +.TP +.PD +.B \-x \fIregex\fP +Regular expression for input files to exclude. + +.SH compress command +Compress or uncompress all files or a selected entry. +.P +Required arguments: +.TP 15 +.PD +.B \-c \fIalgo\fP +Compression algorithm (see +.SM +.B COMPRESSION +) +.TP +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B -e \fIentry\fP +Name of \fIentry\fP to work on (must include PHAR internal +directory name if any). + +.SH delete command +Delete entry from a PHAR archive +.P +Required arguments: +.TP 15 +.PD +.B \-e \fIentry\fP +Name of \fIentry\fP to work on (must include PHAR internal +directory name if any). +.TP +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. + +.SH extract command +Extract a PHAR package to a directory. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B -i \fIregex\fP +Specifies a regular expression for input files. +.TP +.PD +.B -x \fIregex\fP +Regular expression for input files to exclude. +.TP +.PD +.B ... +Directory to extract to (defaults to '.'). + + +.SH help command +This help or help for a selected command. +.P +Optional arguments: +.TP 15 +.PD +.B ... +Optional command to retrieve help for. + +.SH help-list command +Lists available commands. + +.SH info command +Get information about a PHAR package. +.P +By using -k it is possible to return a single value. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B -k \fIindex\fP +Subscription \fIindex\fP to work on. + +.SH list command +List contents of a PHAR archive. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B -i \fIregex\fP +Specifies a regular expression for input files. +.TP +.PD +.B -x \fIregex\fP +Regular expression for input files to exclude. + + +.SH meta-del command +Delete meta information of a PHAR entry or a PHAR package. +.P +If -k is given then the metadata is expected to be an array and the +given index is being deleted. +.P +If something was deleted the return value is 0 otherwise it is 1. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B -e \fIentry\fP +Name of \fIentry\fP to work on (must include PHAR internal +directory name if any). +.TP +.PD +.B -k \fIindex\fP +Subscription \fIindex\fP to work on. + +.SH meta-get command +Get meta information of a PHAR entry or a PHAR package in serialized from. If +no output file is specified for meta data then stdout is being used. +You can also specify a particular index using -k. In that case the +metadata is expected to be an array and the value of the given index +is returned using echo rather than using serialize. If that index does +not exist or no meta data is present then the return value is 1. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B -e \fIentry\fP +Name of \fIentry\fP to work on (must include PHAR internal +directory name if any). +.TP +.PD +.B -k \fIindex\fP +Subscription \fIindex\fP to work on. + +.SH meta-set command +Set meta data of a PHAR entry or a PHAR package using serialized input. If no +input file is specified for meta data then stdin is being used. You can +also specify a particular index using -k. In that case the metadata is +expected to be an array and the value of the given index is being set. +If the metadata is not present or empty a new array will be created. +If the metadata is present and a flat value then the return value is +1. Also using -k the input is been taken directly rather then being +serialized. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.TP +.PD +.B -m \fImeta\fP +Meta data to store with entry (serialized php data). +.P +Optional arguments: +.TP 15 +.PD +.B -e \fIentry\fP +Name of \fIentry\fP to work on (must include PHAR internal +directory name if any). +.TP +.PD +.B -k \fIindex\fP +Subscription \fIindex\fP to work on. + +.SH pack command +Pack files into a PHAR archive. +.P +When using -s <stub>, then the stub file is being excluded from the +list of input files/dirs.To create an archive that contains PEAR class +PHP_Archive then point -p argument to PHP/Archive.php. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.TP +.PD +.B ... +Any number of input files and directories. If -i is in +use then ONLY files and matching the given regular +expression are being packed. If -x is given then files +matching that regular expression are NOT being packed. +.P +Optional arguments: +.TP 15 +.PD +.B \-a \fIalias\fP +Provide an \fIalias\fP name for the phar file. +.TP +.PD +.B \-b \fIbang\fP +Hash-bang line to start the archive (e.g. #!/usr/bin/php). +The hash mark itself '#!' and the newline character are optional. +.TP +.PD +.B \-c \fIalgo\fP +Compression algorithm (see +.SM +.B COMPRESSION +) +.TP +.PD +.B \-h \fIhash\fP +Selects the \fIhash\fP algorithm (see +.SM +.B HASH +) +.TP +.PD +.B \-i \fIregex\fP +Specifies a regular expression for input files. +.TP +.PD +.B \-l \fIlevel\fP +Number of preceding subdirectories to strip from file entries +.TP +.PD +.B \-p \fIloader\fP +Location of PHP_Archive class file (pear list-files +PHP_Archive).You can use '0' or '1' to locate it +automatically using the mentioned pear command. When +using '0' the command does not error out when the class +file cannot be located. This switch also adds some code +around the stub so that class PHP_Archive gets +registered as phar:// stream wrapper if necessary. And +finally this switch will add the file phar.inc from +this package and load it to ensure class Phar is +present. +.TP +.PD +.B \-s \fIstub\fP +Select the \fIstub\fP file. +.TP +.PD +.B \-x \fIregex\fP +Regular expression for input files to exclude. +.TP +.PD +.B \-y \fIkey\fP +Private \fIkey\fP for OpenSSL signing. + +.SH sign command +Set signature hash algorithm. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.TP +.PD +.B \-h \fIhash\fP +Selects the \fIhash\fP algorithm (see +.SM +.B HASH +) +.P +Optional arguments: +.TP 15 +.PD +.B \-y \fIkey\fP +Private \fIkey\fP for OpenSSL signing. + +.SH stub-get command +Get the stub of a PHAR file. If no output file is specified as stub then stdout +is being used. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B \-s \fIstub\fP +Select the \fIstub\fP file. + +.SH stub-set command +Set the stub of a PHAR file. If no input file is specified as stub then stdin +is being used. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B \-b \fIbang\fP +Hash-bang line to start the archive (e.g. #!/usr/bin/php). +The hash mark itself '#!' and the newline character are optional. +.TP +.PD +.B \-p \fIloader\fP +Location of PHP_Archive class file (pear list-files +PHP_Archive).You can use '0' or '1' to locate it +automatically using the mentioned pear command. When +using '0' the command does not error out when the class +file cannot be located. This switch also adds some code +around the stub so that class PHP_Archive gets +registered as phar:// stream wrapper if necessary. And +finally this switch will add the file phar.inc from +this package and load it to ensure class Phar is +present. +.TP +.PD +.B \-s \fIstub\fP +Select the \fIstub\fP file. + + +.SH tree command +Get a directory tree for a PHAR archive. +.P +Required arguments: +.TP 15 +.PD +.B -f \fIfile\fP +Specifies the phar \fIfile\fP to work on. +.P +Optional arguments: +.TP 15 +.PD +.B \-i \fIregex\fP +Specifies a regular expression for input files. +.TP +.PD +.B \-x \fIregex\fP +Regular expression for input files to exclude. + +.SH version command +Get information about the PHAR environment and the tool version. + + +.SH COMPRESSION +Algorithms: +.TP 15 +.PD +.B 0 +No compression +.TP +.PD +.B none +No compression +.TP +.PD +.B auto +Automatically select compression algorithm +.TP +.PD +.B gz +GZip compression +.TP +.PD +.B gzip +GZip compression +.TP +.PD +.B bz2 +BZip2 compression +.TP +.PD +.B bzip2 +BZip2 compression + +.SH HASH +Algorithms: +.TP 15 +.PD +.TP +.PD +.B md5 +MD5 +.TP +.PD +.B sha1 +SHA1 +.TP +.PD +.B sha256 +SHA256 +.TP +.PD +.B sha512 +SHA512 +.TP +.PD +.B openssl +OpenSSL + +.SH SEE ALSO +For a more or less complete description of PHAR look here: +.PD 0 +.P +.B http://php.net/phar +.PD 1 +.P +.SH BUGS +You can view the list of known bugs or report any new bug you +found at: +.PD 0 +.P +.B http://bugs.php.net +.PD 1 +.SH AUTHORS +The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski. +.P +Work for the PHP archive was done by Gregory Beaver, Marcus Boerger. +.P +A List of active developers can be found here: +.PD 0 +.P +.B http://www.php.net/credits.php +.PD 1 +.P +And last but not least PHP was developed with the help of a huge amount of +contributors all around the world. +.SH VERSION INFORMATION +This manpage describes \fBphar\fP, version @PHP_VERSION@. +.SH COPYRIGHT +Copyright \(co 1997\-2013 The PHP Group +.LP +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 +available through the world-wide-web at the following url: +.PD 0 +.P +.B http://www.php.net/license/3_01.txt +.PD 1 +.P +If you did not receive a copy of the PHP license and are unable to +obtain it through the world-wide-web, please send a note to +.B license@php.net +so we can mail you a copy immediately. diff --git a/ext/phar/phar.c b/ext/phar/phar.c index c5042cc34..c85687ef5 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2579,6 +2579,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, php_serialize_data_t metadata_hash; smart_str main_metadata_str = {0}; int free_user_stub, free_fp = 1, free_ufp = 1; + int manifest_hack = 0; if (phar->is_persistent) { if (error) { @@ -2930,6 +2931,12 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, manifest_len = offset + phar->alias_len + sizeof(manifest) + main_metadata_str.len; phar_set_32(manifest, manifest_len); + /* Hack - see bug #65028, add padding byte to the end of the manifest */ + if(manifest[0] == '\r' || manifest[0] == '\n') { + manifest_len++; + phar_set_32(manifest, manifest_len); + manifest_hack = 1; + } phar_set_32(manifest+4, new_manifest_count); if (has_dirs) { *(manifest + 8) = (unsigned char) (((PHAR_API_VERSION) >> 8) & 0xFF); @@ -3054,6 +3061,22 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, return EOF; } } + /* Hack - see bug #65028, add padding byte to the end of the manifest */ + if(manifest_hack) { + if(1 != php_stream_write(newfile, manifest, 1)) { + if (closeoldfile) { + php_stream_close(oldfile); + } + + php_stream_close(newfile); + + if (error) { + spprintf(error, 0, "unable to write manifest padding byte"); + } + + return EOF; + } + } /* now copy the actual file data to the new phar */ offset = php_stream_tell(newfile); diff --git a/ext/phar/phar.phar.1.in b/ext/phar/phar.phar.1.in new file mode 100644 index 000000000..b5eecbfeb --- /dev/null +++ b/ext/phar/phar.phar.1.in @@ -0,0 +1 @@ +.so man1/phar.1 diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index a6dd2c814..aeb11851c 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1899,6 +1899,10 @@ PHP_METHOD(Phar, buildFromDirectory) pass.count = 0; pass.ret = return_value; pass.fp = php_stream_fopen_tmpfile(); + if (pass.fp == NULL) { + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar \"%s\" unable to create temporary file", phar_obj->arc.archive->fname); + return; + } if (phar_obj->arc.archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->arc.archive) TSRMLS_CC)) { zval_ptr_dtor(&iteriter); @@ -1979,6 +1983,10 @@ PHP_METHOD(Phar, buildFromIterator) pass.ret = return_value; pass.count = 0; pass.fp = php_stream_fopen_tmpfile(); + if (pass.fp == NULL) { + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar \"%s\": unable to create temporary file", phar_obj->arc.archive->fname); + return; + } if (SUCCESS == spl_iterator_apply(obj, (spl_iterator_apply_func_t) phar_build, (void *) &pass TSRMLS_CC)) { phar_obj->arc.archive->ufp = pass.fp; @@ -2311,6 +2319,10 @@ static zval *phar_convert_to_other(phar_archive_data *source, int convert, char zend_get_hash_value, NULL, 0); phar->fp = php_stream_fopen_tmpfile(); + if (phar->fp == NULL) { + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "unable to create temporary file"); + return NULL; + } phar->fname = source->fname; phar->fname_len = source->fname_len; phar->is_temporary_alias = source->is_temporary_alias; diff --git a/ext/phar/tar.c b/ext/phar/tar.c index f17033543..0e60e3db1 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -847,7 +847,10 @@ int phar_tar_setmetadata(zval *metadata, phar_entry_info *entry, char **error TS entry->is_modified = 1; entry->fp = php_stream_fopen_tmpfile(); entry->offset = entry->offset_abs = 0; - + if (entry->fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return -1; + } if (entry->metadata_str.len != php_stream_write(entry->fp, entry->metadata_str.c, entry->metadata_str.len)) { spprintf(error, 0, "phar tar error: unable to write metadata to magic metadata file \"%s\"", entry->filename); zend_hash_del(&(entry->phar->manifest), entry->filename, entry->filename_len); @@ -949,7 +952,10 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defau entry.filename = estrndup(".phar/alias.txt", sizeof(".phar/alias.txt")-1); entry.filename_len = sizeof(".phar/alias.txt")-1; entry.fp = php_stream_fopen_tmpfile(); - + if (entry.fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return -1; + } 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 tar-based phar \"%s\"", phar->fname); @@ -1014,6 +1020,10 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defau 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) @@ -1038,7 +1048,10 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defau } 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) { @@ -1087,7 +1100,6 @@ nostub: } newfile = php_stream_fopen_tmpfile(); - if (!newfile) { if (error) { spprintf(error, 0, "unable to create temporary file"); @@ -1174,7 +1186,10 @@ nostub: entry.filename = ".phar/signature.bin"; entry.filename_len = sizeof(".phar/signature.bin")-1; entry.fp = php_stream_fopen_tmpfile(); - + if (entry.fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return EOF; + } #ifdef WORDS_BIGENDIAN # define PHAR_SET_32(var, buffer) \ *(php_uint32 *)(var) = (((((unsigned char*)&(buffer))[3]) << 24) \ diff --git a/ext/phar/tests/bug65028.phpt b/ext/phar/tests/bug65028.phpt new file mode 100644 index 000000000..74273b850 --- /dev/null +++ b/ext/phar/tests/bug65028.phpt @@ -0,0 +1,156 @@ +--TEST-- +Phar - test specific manifest length +--INI-- +phar.readonly=0 +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php + +$files = array( + "lib/widgets/Widgets.php", + "lib/events/FormBeginEventArgs.php", + "lib/events/FormEndEventArgs.php", + "lib/Core.php", + "lib/database/MySqlDatabase.php", + "lib/utils/DateUtil.php", + "js/global.js", + "files/_emptyDirectory", + "files/search/schema.xml", + "vendor/Fusonic/Linq/Internal/WhereIterator.php", + "vendor/Fusonic/Linq/Internal/SelectManyIterator.php", + "vendor/Fusonic/Linq/Internal/SelectIterator.php", + "vendor/Fusonic/Linq/Internal/DiffIterator.php", + "vendor/Fusonic/Linq/Internal/GroupIterator.php", + "vendor/Fusonic/Linq/Internal/DistinctIterator.php", + "vendor/Fusonic/Linq/Internal/LinqHelper.php", + "vendor/Fusonic/Linq/Internal/OrderIterator.php", + "vendor/Fusonic/Linq/Internal/IntersectIterator.php", + "vendor/Fusonic/Linq/GroupedLinq.php", + "vendor/Fusonic/Linq.php", + "vendor/Fusonic/UI/Widgets/Forms/FormBegin.php", + "vendor/Fusonic/UI/Widgets/Forms/FormSectionBuilder.php", + "vendor/Fusonic/UI/Widgets/Forms/AutoSelect.php", + "vendor/Fusonic/UI/Widgets/Forms/ControlGroup.php", + "vendor/Fusonic/UI/Widgets/Forms/FormEnd.php", + "vendor/Fusonic/UI/Widgets/WidgetBase.php", + "modules/calendar/ajax/calendarGetInvitedUsersContentAjaxHandler.php", + "modules/calendar/js/calendarAppointmentForm.js", + "modules/calendar/misc/calendarAppointment.php", + "modules/calendar/pages/forms/calendarAppointmentForm.php", + "modules/calendar/setup/config.xml", + "modules/cmt/js/cmtMicroCommentsWidget.js", + "modules/cmt/setup/config.xml", + "modules/meta/misc/metaContentHelper.php", + "modules/meta/setup/config.xml", + "modules/brd/misc/brdPostStreamFormatter.php", + "modules/brd/misc/brdPost.php", + "modules/brd/setup/config/streamContents.xml", + "modules/brd/setup/resources/lang/en.xml", + "modules/brd/setup/resources/lang/de.xml", + "modules/brd/setup/config.xml", + "modules/auth/misc/authLoginService.php", + "modules/auth/setup/config.xml", + "modules/bwd/cache/bwdWordCacheCreator.php", + "modules/bwd/bwd.php", + "modules/bwd/setup/config.xml", + "modules/nws/templates/pages/forms/nwsNewsForm.tpl", + "modules/nws/templates/pages/nwsShowNewsPage.tpl", + "modules/nws/pages/forms/nwsNewsForm.php", + "modules/nws/pages/nwsShowNewsPage.php", + "modules/nws/setup/config.xml", + "modules/gmp/cache/gmpMarkersCacheCreator.php", + "modules/gmp/select/gmpMapContentSelect.php", + "modules/gmp/templates/gmpShowAppointmentPage.tpl", + "modules/gmp/templates/gmpShowLinkPage.tpl", + "modules/gmp/setup/config.xml", + "modules/mul/cache/mulVideoPortalCacheCreator.php", + "modules/mul/misc/mulPermissionHelper.php", + "modules/mul/templates/widgets/mulFileEmbedWidget_Video_Flv.tpl", + "modules/mul/setup/config/mulUploadVideoPortalMatches.xml", + "modules/mul/setup/config.xml", + "modules/cat/select/catCategorySelect.php", + "modules/cat/misc/catCategory.php", + "modules/cat/templates/pages/forms/catCategoryForm.tpl", + "modules/cat/pages/forms/catEditCategoryForm.php", + "modules/cat/pages/forms/catAddCategoryForm.php", + "modules/cat/setup/config.xml", + "modules/sty/events/styPageShowEventHandler.php", + "modules/sty/misc/styBox.php", + "modules/sty/templates/pages/forms/styLayoutForm.tpl", + "modules/sty/templates/pages/forms/styBoxForm.tpl", + "modules/sty/templates/pages/forms/styVariantForm.tpl", + "modules/sty/setup/resources/lang/en.xml", + "modules/sty/setup/resources/lang/de.xml", + "modules/sty/setup/config.xml", + "modules/reg/misc/regRegistrationHelper.php", + "modules/reg/setup/config.xml", + "modules/not/misc/notEmailNotificationProvider.php", + "modules/not/setup/config.xml", + "modules/styfusonic/setup/config.xml", + "modules/sys/ajax/sysUserAutoSuggestSelectAjaxHandler.php", + "modules/sys/js/sysUserAutoSuggestSelect.js", + "modules/sys/select/sysPermissionSelect.php", + "modules/sys/misc/sysHtaccessConfigWriter.php", + "modules/sys/misc/sysUserRepository.php", + "modules/sys/setup/resources/lang/en.xml", + "modules/sys/setup/resources/lang/de.xml", + "modules/sys/setup/config.xml", + "modules/igr/boxes/igrGreatestEntriesBoxTab.php", + "modules/igr/boxes/igrTopRatedEntriesBoxTab.php", + "modules/igr/setup/config.xml", + "modules/rat/ajax/ratRateAjaxHandler.php", + "modules/rat/ajax/ratUnlikeAjaxHandler.php", + "modules/rat/setup/config.xml", + "modules/search/select/searchModuleSelect.php", + "modules/search/select/searchOrderSelect.php", + "modules/search/misc/searchResultFormatter.php", + "modules/search/misc/searchProviderSolr.php", + "modules/search/misc/searchProviderLucene.php", + "modules/search/misc/searchResultItem.php", + "modules/search/misc/searchProviderBase.php", + "modules/search/misc/searchIProvider.php", + "modules/search/templates/misc/searchResultFormatter.tpl", + "modules/search/templates/pages/searchIndexPage.tpl", + "modules/search/templates/pages/forms/searchSearchForm.tpl", + "modules/search/pages/forms/searchSearchForm.php", + "modules/search/css/searchResultFormatter.css", + "modules/search/setup/config/sysSettings.xml", + "modules/search/setup/resources/lang/en.xml", + "modules/search/setup/resources/lang/de.xml", + "modules/search/setup/config.xml", + "style/Fusonic/40components.css", + "style/_emptyDirectory", + "index.php", +// "a", // This will make the test pass +); + +// Create Phar with the filenames above +$phar = new Phar(__DIR__ . "/bug65028.phar"); +foreach($files as $file) +{ + $phar->addFromString($file, ""); +} + +// Copy phar +copy(__DIR__ . "/bug65028.phar", __DIR__ . "/bug65028-copy.phar"); + +// Open phar +try +{ + $phar = new Phar(__DIR__ . "/bug65028-copy.phar"); + echo "No exception thrown.\n"; +} +catch(UnexpectedValueException $ex) +{ + echo "Exception thrown: " . $ex->getMessage() . "\n"; +} +?> +--CLEAN-- +<?php +@unlink(__DIR__ . "/bug65028.phar"); +@unlink(__DIR__ . "/bug65028-copy.phar"); +?> +--EXPECT-- +No exception thrown. + diff --git a/ext/phar/tests/files/openssl.cnf b/ext/phar/tests/files/openssl.cnf index 10e69076c..4ed40fdc8 100644 --- a/ext/phar/tests/files/openssl.cnf +++ b/ext/phar/tests/files/openssl.cnf @@ -3,7 +3,7 @@ default_bits = 1024 default_keyfile = privkey.pem distinguished_name = req_distinguished_name attributes = req_attributes -x509_extensions = v3_ca # The extentions to add to the self signed cert +x509_extensions = v3_ca # The extensions to add to the self signed cert string_mask = MASK:4294967295 diff --git a/ext/phar/util.c b/ext/phar/util.c index 05c90cd45..898d8bd4b 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -889,6 +889,10 @@ int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **er dest->offset = 0; dest->is_modified = 1; dest->fp = php_stream_fopen_tmpfile(); + if (dest->fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return EOF; + } phar_seek_efp(source, 0, SEEK_SET, 0, 1 TSRMLS_CC); link = phar_get_link_source(source TSRMLS_CC); @@ -1129,6 +1133,10 @@ int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) /* {{ } fp = php_stream_fopen_tmpfile(); + if (fp == NULL) { + spprintf(error, 0, "phar error: unable to create temporary file"); + return FAILURE; + } phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC); link = phar_get_link_source(entry TSRMLS_CC); diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 33732fbd6..6ba745e9c 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -937,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: @@ -1095,6 +1096,10 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas 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); @@ -1122,6 +1127,10 @@ static int phar_zip_applysignature(phar_archive_data *phar, struct _phar_zip_pas 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); @@ -1192,7 +1201,10 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, long len, int defau /* 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); @@ -1267,6 +1279,10 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, long len, int defau 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) @@ -1300,7 +1316,10 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, long len, int defau } 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) { |