summaryrefslogtreecommitdiff
path: root/ext/phar/phar.c
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2013-07-23 21:44:06 -0700
committerStanislav Malyshev <stas@php.net>2013-07-23 21:44:06 -0700
commit96a53f6715ac563fa70f2db231478ecd0d313ff0 (patch)
treeb36f76b449c1283d2165073d1d419fd5eee3870c /ext/phar/phar.c
parentc28ab73d7346e332594c30a9a544cfd74b8bc5bb (diff)
parentf8efdc2b4bca2a8f7e57aae36a01df044ba3d0b5 (diff)
downloadphp-git-96a53f6715ac563fa70f2db231478ecd0d313ff0.tar.gz
Merge branch 'bug65028' into PHP-5.4
* bug65028: fix bug #65028 Phar::buildFromDirectory creates corrupt archives for some specific contents
Diffstat (limited to 'ext/phar/phar.c')
-rw-r--r--ext/phar/phar.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index c5042cc34a..c85687ef5c 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);