version 1.1.1.1, 2012/02/21 23:47:59
|
version 1.1.1.2, 2013/07/22 01:31:59
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| TAR archive support for Phar | |
| TAR archive support for Phar | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 2005-2012 The PHP Group | | | Copyright (c) 2005-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| 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 | |
| that is bundled with this package in the file LICENSE, and is | |
Line 38 static php_uint32 phar_tar_number(char *buf, int len)
|
Line 38 static php_uint32 phar_tar_number(char *buf, int len)
|
/* }}} */ |
/* }}} */ |
|
|
/* adapted from format_octal() in libarchive |
/* adapted from format_octal() in libarchive |
* | * |
* Copyright (c) 2003-2009 Tim Kientzle |
* Copyright (c) 2003-2009 Tim Kientzle |
* All rights reserved. |
* All rights reserved. |
* |
* |
Line 161 static int phar_tar_process_metadata(phar_entry_info *
|
Line 161 static int phar_tar_process_metadata(phar_entry_info *
|
size_t save = php_stream_tell(fp), read; |
size_t save = php_stream_tell(fp), read; |
phar_entry_info *mentry; |
phar_entry_info *mentry; |
|
|
metadata = (char *) emalloc(entry->uncompressed_filesize + 1); | metadata = (char *) safe_emalloc(1, entry->uncompressed_filesize, 1); |
|
|
read = php_stream_read(fp, metadata, entry->uncompressed_filesize); |
read = php_stream_read(fp, metadata, entry->uncompressed_filesize); |
if (read != entry->uncompressed_filesize) { |
if (read != entry->uncompressed_filesize) { |
Line 337 bail:
|
Line 337 bail:
|
last_was_longlink = 1; |
last_was_longlink = 1; |
/* support the ././@LongLink system for storing long filenames */ |
/* support the ././@LongLink system for storing long filenames */ |
entry.filename_len = entry.uncompressed_filesize; |
entry.filename_len = entry.uncompressed_filesize; |
|
|
|
/* Check for overflow - bug 61065 */ |
|
if (entry.filename_len == UINT_MAX) { |
|
if (error) { |
|
spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (invalid entry size)", fname); |
|
} |
|
php_stream_close(fp); |
|
phar_destroy_phar_data(myphar TSRMLS_CC); |
|
return FAILURE; |
|
} |
entry.filename = pemalloc(entry.filename_len+1, myphar->is_persistent); |
entry.filename = pemalloc(entry.filename_len+1, myphar->is_persistent); |
|
|
read = php_stream_read(fp, entry.filename, entry.filename_len); |
read = php_stream_read(fp, entry.filename, entry.filename_len); |
Line 367 bail:
|
Line 377 bail:
|
} |
} |
|
|
read = php_stream_read(fp, buf, sizeof(buf)); |
read = php_stream_read(fp, buf, sizeof(buf)); |
| |
if (read != sizeof(buf)) { |
if (read != sizeof(buf)) { |
efree(entry.filename); |
efree(entry.filename); |
if (error) { |
if (error) { |
Line 837 int phar_tar_setmetadata(zval *metadata, phar_entry_in
|
Line 847 int phar_tar_setmetadata(zval *metadata, phar_entry_in
|
entry->is_modified = 1; |
entry->is_modified = 1; |
entry->fp = php_stream_fopen_tmpfile(); |
entry->fp = php_stream_fopen_tmpfile(); |
entry->offset = entry->offset_abs = 0; |
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)) { |
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); |
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); |
zend_hash_del(&(entry->phar->manifest), entry->filename, entry->filename_len); |
Line 939 int phar_tar_flush(phar_archive_data *phar, char *user
|
Line 952 int phar_tar_flush(phar_archive_data *phar, char *user
|
entry.filename = estrndup(".phar/alias.txt", sizeof(".phar/alias.txt")-1); |
entry.filename = estrndup(".phar/alias.txt", sizeof(".phar/alias.txt")-1); |
entry.filename_len = sizeof(".phar/alias.txt")-1; |
entry.filename_len = sizeof(".phar/alias.txt")-1; |
entry.fp = php_stream_fopen_tmpfile(); |
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 (phar->alias_len != (int)php_stream_write(entry.fp, phar->alias, phar->alias_len)) { |
if (error) { |
if (error) { |
spprintf(error, 0, "unable to set alias in tar-based phar \"%s\"", phar->fname); |
spprintf(error, 0, "unable to set alias in tar-based phar \"%s\"", phar->fname); |
Line 976 int phar_tar_flush(phar_archive_data *phar, char *user
|
Line 992 int phar_tar_flush(phar_archive_data *phar, char *user
|
len = -len; |
len = -len; |
} |
} |
user_stub = 0; |
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) { |
if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) { |
#endif |
|
if (error) { |
if (error) { |
spprintf(error, 0, "unable to read resource to copy stub to new tar-based phar \"%s\"", phar->fname); |
spprintf(error, 0, "unable to read resource to copy stub to new tar-based phar \"%s\"", phar->fname); |
} |
} |
Line 1007 int phar_tar_flush(phar_archive_data *phar, char *user
|
Line 1020 int phar_tar_flush(phar_archive_data *phar, char *user
|
|
|
len = pos - user_stub + 18; |
len = pos - user_stub + 18; |
entry.fp = php_stream_fopen_tmpfile(); |
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; |
entry.uncompressed_filesize = len + 5; |
|
|
if ((size_t)len != php_stream_write(entry.fp, user_stub, len) |
if ((size_t)len != php_stream_write(entry.fp, user_stub, len) |
Line 1031 int phar_tar_flush(phar_archive_data *phar, char *user
|
Line 1048 int phar_tar_flush(phar_archive_data *phar, char *user
|
} else { |
} else { |
/* Either this is a brand new phar (add the stub), or the default stub is required (overwrite the stub) */ |
/* 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(); |
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)) { |
if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { |
php_stream_close(entry.fp); |
php_stream_close(entry.fp); |
if (error) { |
if (error) { |
Line 1080 nostub:
|
Line 1100 nostub:
|
} |
} |
|
|
newfile = php_stream_fopen_tmpfile(); |
newfile = php_stream_fopen_tmpfile(); |
|
|
if (!newfile) { |
if (!newfile) { |
if (error) { |
if (error) { |
spprintf(error, 0, "unable to create temporary file"); |
spprintf(error, 0, "unable to create temporary file"); |
Line 1167 nostub:
|
Line 1186 nostub:
|
entry.filename = ".phar/signature.bin"; |
entry.filename = ".phar/signature.bin"; |
entry.filename_len = sizeof(".phar/signature.bin")-1; |
entry.filename_len = sizeof(".phar/signature.bin")-1; |
entry.fp = php_stream_fopen_tmpfile(); |
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 |
#ifdef WORDS_BIGENDIAN |
# define PHAR_SET_32(var, buffer) \ |
# define PHAR_SET_32(var, buffer) \ |
*(php_uint32 *)(var) = (((((unsigned char*)&(buffer))[3]) << 24) \ |
*(php_uint32 *)(var) = (((((unsigned char*)&(buffer))[3]) << 24) \ |