summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-08-07 16:47:50 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-08-07 16:47:50 +0200
commit7b9f37c3893a9a1c942a04a09c9e6b172c4af80b (patch)
treecf590bb05dd645f42edb1325ecedef1ef795c494 /ext
parent45ece5bf195e47d81df52da0c3e07b07d671fcf8 (diff)
downloadphp-git-7b9f37c3893a9a1c942a04a09c9e6b172c4af80b.tar.gz
Fix ZPP order in ext/phar
Diffstat (limited to 'ext')
-rw-r--r--ext/phar/phar_object.c240
1 files changed, 134 insertions, 106 deletions
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 61a6473aca..c72fecc6e3 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -1703,6 +1703,10 @@ PHP_METHOD(Phar, buildFromDirectory)
zval arg, arg2, iter, iteriter, regexiter;
struct _phar_t pass;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &dir, &dir_len, &regex, &regex_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -1711,10 +1715,6 @@ PHP_METHOD(Phar, buildFromDirectory)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &dir, &dir_len, &regex, &regex_len) == FAILURE) {
- RETURN_THROWS();
- }
-
if (ZEND_SIZE_T_UINT_OVFL(dir_len)) {
RETURN_FALSE;
}
@@ -1838,6 +1838,10 @@ PHP_METHOD(Phar, buildFromIterator)
char *base = NULL;
struct _phar_t pass;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -1846,10 +1850,6 @@ PHP_METHOD(Phar, buildFromIterator)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
- RETURN_THROWS();
- }
-
if (ZEND_SIZE_T_UINT_OVFL(base_len)) {
RETURN_FALSE;
}
@@ -1891,12 +1891,13 @@ PHP_METHOD(Phar, count)
{
/* mode can be ignored, maximum depth is 1 */
zend_long mode;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mode) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
RETURN_LONG(zend_hash_num_elements(&phar_obj->archive->manifest));
}
/* }}} */
@@ -1907,12 +1908,13 @@ PHP_METHOD(Phar, count)
PHP_METHOD(Phar, isFileFormat)
{
zend_long type;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &type) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
switch (type) {
case PHAR_FORMAT_TAR:
RETURN_BOOL(phar_obj->archive->is_tar);
@@ -2341,12 +2343,13 @@ PHP_METHOD(Phar, convertToExecutable)
zend_object *ret;
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday, so there) */
zend_long format = 9021976, method = 9021976;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls", &format, &method, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly)) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
"Cannot write out executable phar archive, phar is read-only");
@@ -2444,12 +2447,13 @@ PHP_METHOD(Phar, convertToData)
zend_object *ret;
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday so there) */
zend_long format = 9021976, method = 9021976;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls", &format, &method, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
switch (format) {
case 9021976:
case PHAR_FORMAT_SAME: /* null is converted to 0 */
@@ -2538,12 +2542,12 @@ PHP_METHOD(Phar, convertToData)
*/
PHP_METHOD(Phar, isCompressed)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (phar_obj->archive->flags & PHAR_FILE_COMPRESSED_GZ) {
RETURN_LONG(PHAR_ENT_COMPRESSED_GZ);
}
@@ -2560,12 +2564,13 @@ PHP_METHOD(Phar, isCompressed)
PHP_METHOD(Phar, isWritable)
{
php_stream_statbuf ssb;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (!phar_obj->archive->is_writeable) {
RETURN_FALSE;
}
@@ -2589,6 +2594,11 @@ PHP_METHOD(Phar, delete)
size_t fname_len;
char *error;
phar_entry_info *entry;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -2597,10 +2607,6 @@ PHP_METHOD(Phar, delete)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
- RETURN_THROWS();
- }
-
if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
RETURN_THROWS();
@@ -2635,12 +2641,12 @@ PHP_METHOD(Phar, delete)
/* {{{ Returns the alias for the Phar or NULL. */
PHP_METHOD(Phar, getAlias)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (phar_obj->archive->alias && phar_obj->archive->alias != phar_obj->archive->fname) {
RETURN_STRINGL(phar_obj->archive->alias, phar_obj->archive->alias_len);
}
@@ -2650,12 +2656,12 @@ PHP_METHOD(Phar, getAlias)
/* {{{ Returns the real path to the phar archive on disk */
PHP_METHOD(Phar, getPath)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
RETURN_STRINGL(phar_obj->archive->fname, phar_obj->archive->fname_len);
}
/* }}} */
@@ -2670,6 +2676,10 @@ PHP_METHOD(Phar, setAlias)
size_t alias_len, oldalias_len;
int old_temp, readd = 0;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &alias, &alias_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -2764,12 +2774,12 @@ valid_alias:
/* {{{ Return version info of Phar archive */
PHP_METHOD(Phar, getVersion)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
RETURN_STRING(phar_obj->archive->version);
}
/* }}} */
@@ -2777,12 +2787,12 @@ PHP_METHOD(Phar, getVersion)
/* {{{ Do not flush a writeable phar (save its contents) until explicitly requested */
PHP_METHOD(Phar, startBuffering)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
phar_obj->archive->donotflush = 1;
}
/* }}} */
@@ -2790,12 +2800,12 @@ PHP_METHOD(Phar, startBuffering)
/* {{{ Returns whether write operations are flushing to disk immediately. */
PHP_METHOD(Phar, isBuffering)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
RETURN_BOOL(phar_obj->archive->donotflush);
}
/* }}} */
@@ -2805,12 +2815,12 @@ PHP_METHOD(Phar, stopBuffering)
{
char *error;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
"Cannot write out phar archive, phar is read-only");
@@ -2837,6 +2847,7 @@ PHP_METHOD(Phar, setStub)
size_t stub_len;
zend_long len = -1;
php_stream *stream;
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -2893,7 +2904,7 @@ PHP_METHOD(Phar, setStub)
RETURN_TRUE;
}
- RETURN_FALSE;
+ RETURN_THROWS();
}
/* }}} */
@@ -2915,6 +2926,11 @@ PHP_METHOD(Phar, setDefaultStub)
zend_string *stub = NULL;
size_t index_len = 0, webindex_len = 0;
int created_stub = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (phar_obj->archive->is_data) {
@@ -2928,10 +2944,6 @@ PHP_METHOD(Phar, setDefaultStub)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
- RETURN_THROWS();
- }
-
if (ZEND_NUM_ARGS() > 0 && (phar_obj->archive->is_tar || phar_obj->archive->is_zip)) {
php_error_docref(NULL, E_WARNING, "Method accepts no arguments for a tar- or zip-based phar stub, %d given", ZEND_NUM_ARGS());
RETURN_FALSE;
@@ -2989,6 +3001,10 @@ PHP_METHOD(Phar, setSignatureAlgorithm)
char *error, *key = NULL;
size_t key_len = 0;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &algo, &key, &key_len) != SUCCESS) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -2997,10 +3013,6 @@ PHP_METHOD(Phar, setSignatureAlgorithm)
RETURN_THROWS();
}
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "l|s", &algo, &key, &key_len) != SUCCESS) {
- return;
- }
-
switch (algo) {
case PHAR_SIG_SHA256:
case PHAR_SIG_SHA512:
@@ -3032,12 +3044,12 @@ PHP_METHOD(Phar, setSignatureAlgorithm)
/* {{{ Returns a hash signature, or FALSE if the archive is unsigned. */
PHP_METHOD(Phar, getSignature)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (phar_obj->archive->signature) {
zend_string *unknown;
@@ -3073,12 +3085,12 @@ PHP_METHOD(Phar, getSignature)
/* {{{ Return whether phar was modified */
PHP_METHOD(Phar, getModified)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
RETURN_BOOL(phar_obj->archive->is_modified);
}
/* }}} */
@@ -3151,12 +3163,13 @@ PHP_METHOD(Phar, compress)
size_t ext_len = 0;
uint32_t flags;
zend_object *ret;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s", &method, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
"Cannot compress phar archive, phar is read-only");
@@ -3216,12 +3229,13 @@ PHP_METHOD(Phar, decompress)
char *ext = NULL;
size_t ext_len = 0;
zend_object *ret;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
"Cannot decompress phar archive, phar is read-only");
@@ -3257,12 +3271,13 @@ PHP_METHOD(Phar, compressFiles)
char *error;
uint32_t flags;
zend_long method;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &method) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
"Phar is readonly, cannot change compression");
@@ -3329,12 +3344,14 @@ PHP_METHOD(Phar, compressFiles)
PHP_METHOD(Phar, decompressFiles)
{
char *error;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
+
}
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
"Phar is readonly, cannot change compression");
@@ -3378,11 +3395,12 @@ PHP_METHOD(Phar, copy)
phar_entry_info *oldentry, newentry = {0}, *temp;
size_t tmp_len = 0;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &oldfile, &oldfile_len, &newfile, &newfile_len) == FAILURE) {
RETURN_THROWS();
}
+
+ PHAR_ARCHIVE_OBJECT();
+
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
"Cannot copy \"%s\" to \"%s\", phar is read-only", oldfile, newfile);
@@ -3472,12 +3490,12 @@ PHP_METHOD(Phar, offsetExists)
size_t fname_len;
phar_entry_info *entry;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) {
if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) {
if (entry->is_deleted) {
@@ -3508,12 +3526,13 @@ PHP_METHOD(Phar, offsetGet)
zval zfname;
phar_entry_info *entry;
zend_string *sfname;
- PHAR_ARCHIVE_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
/* security is 0 here so that we can get a better error message than "entry doesn't exist" */
if (!(entry = phar_get_entry_info_dir(phar_obj->archive, fname, fname_len, 1, &error, 0))) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Entry %s does not exist%s%s", fname, error?", ":"", error?error:"");
@@ -3682,6 +3701,12 @@ PHP_METHOD(Phar, offsetSet)
char *fname, *cont_str = NULL;
size_t fname_len, cont_len;
zval *zresource;
+
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "pr", &fname, &fname_len, &zresource) == FAILURE
+ && zend_parse_parameters(ZEND_NUM_ARGS(), "ps", &fname, &fname_len, &cont_str, &cont_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -3689,10 +3714,6 @@ PHP_METHOD(Phar, offsetSet)
RETURN_THROWS();
}
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "pr", &fname, &fname_len, &zresource) == FAILURE
- && zend_parse_parameters(ZEND_NUM_ARGS(), "ps", &fname, &fname_len, &cont_str, &cont_len) == FAILURE) {
- RETURN_THROWS();
- }
if (fname_len == sizeof(".phar/stub.php")-1 && !memcmp(fname, ".phar/stub.php", sizeof(".phar/stub.php")-1)) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot set stub \".phar/stub.php\" directly in phar \"%s\", use setStub", phar_obj->archive->fname);
RETURN_THROWS();
@@ -3718,14 +3739,15 @@ PHP_METHOD(Phar, offsetUnset)
char *fname, *error;
size_t fname_len;
phar_entry_info *entry;
- PHAR_ARCHIVE_OBJECT();
- if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
- zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly");
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) {
+ PHAR_ARCHIVE_OBJECT();
+
+ if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly");
RETURN_THROWS();
}
@@ -3768,12 +3790,12 @@ PHP_METHOD(Phar, addEmptyDir)
char *dirname;
size_t dirname_len;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &dirname, &dirname_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (dirname_len >= sizeof(".phar")-1 && !memcmp(dirname, ".phar", sizeof(".phar")-1)) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create a directory in magic \".phar\" directory");
RETURN_THROWS();
@@ -3791,12 +3813,12 @@ PHP_METHOD(Phar, addFile)
php_stream *resource;
zval zresource;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &fname, &fname_len, &localname, &localname_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (!strstr(fname, "://") && php_check_open_basedir(fname)) {
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "phar error: unable to open file \"%s\" to add to phar archive, open_basedir restrictions prevent this", fname);
RETURN_THROWS();
@@ -3824,12 +3846,12 @@ PHP_METHOD(Phar, addFromString)
char *localname, *cont_str;
size_t localname_len, cont_len;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps", &localname, &localname_len, &cont_str, &cont_len) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
phar_add_file(&(phar_obj->archive), localname, localname_len, cont_str, cont_len, NULL);
}
/* }}} */
@@ -3843,12 +3865,12 @@ PHP_METHOD(Phar, getStub)
php_stream_filter *filter = NULL;
phar_entry_info *stub;
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
if (phar_obj->archive->is_tar || phar_obj->archive->is_zip) {
if (NULL != (stub = zend_hash_str_find_ptr(&(phar_obj->archive->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1))) {
@@ -3934,12 +3956,12 @@ carry_on:
/* {{{ Returns TRUE if the phar has global metadata, FALSE otherwise. */
PHP_METHOD(Phar, hasMetadata)
{
- PHAR_ARCHIVE_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ARCHIVE_OBJECT();
+
RETURN_BOOL(phar_metadata_tracker_has_data(&phar_obj->archive->metadata_tracker, phar_obj->archive->is_persistent));
}
/* }}} */
@@ -3949,13 +3971,14 @@ PHP_METHOD(Phar, getMetadata)
{
HashTable *unserialize_options = NULL;
phar_metadata_tracker *tracker;
- PHAR_ARCHIVE_OBJECT();
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY_HT(unserialize_options)
ZEND_PARSE_PARAMETERS_END();
+ PHAR_ARCHIVE_OBJECT();
+
tracker = &phar_obj->archive->metadata_tracker;
if (phar_metadata_tracker_has_data(tracker, phar_obj->archive->is_persistent)) {
phar_metadata_tracker_unserialize_or_copy(tracker, return_value, phar_obj->archive->is_persistent, unserialize_options, "Phar::getMetadata");
@@ -4000,6 +4023,10 @@ PHP_METHOD(Phar, setMetadata)
char *error;
zval *metadata;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &metadata) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -4007,10 +4034,6 @@ PHP_METHOD(Phar, setMetadata)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &metadata) == FAILURE) {
- RETURN_THROWS();
- }
-
if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
RETURN_THROWS();
@@ -4036,6 +4059,10 @@ PHP_METHOD(Phar, delMetadata)
{
char *error;
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ARCHIVE_OBJECT();
if (PHAR_G(readonly) && !phar_obj->archive->is_data) {
@@ -4043,10 +4070,6 @@ PHP_METHOD(Phar, delMetadata)
RETURN_THROWS();
}
- if (zend_parse_parameters_none() == FAILURE) {
- RETURN_THROWS();
- }
-
if (!phar_metadata_tracker_has_data(&phar_obj->archive->metadata_tracker, phar_obj->archive->is_persistent)) {
RETURN_TRUE;
}
@@ -4490,12 +4513,12 @@ PHP_METHOD(PharFileInfo, __destruct)
/* {{{ Returns the compressed size */
PHP_METHOD(PharFileInfo, getCompressedSize)
{
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
RETURN_LONG(entry_obj->entry->compressed_filesize);
}
/* }}} */
@@ -4505,12 +4528,13 @@ PHP_METHOD(PharFileInfo, isCompressed)
{
/* a number that is not Phar::GZ or Phar::BZ2 */
zend_long method = 9021976;
- PHAR_ENTRY_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &method) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
switch (method) {
case 9021976:
RETURN_BOOL(entry_obj->entry->flags & PHAR_ENT_COMPRESSION_MASK);
@@ -4528,12 +4552,12 @@ PHP_METHOD(PharFileInfo, isCompressed)
/* {{{ Returns CRC32 code or throws an exception if not CRC checked */
PHP_METHOD(PharFileInfo, getCRC32)
{
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
if (entry_obj->entry->is_dir) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \
"Phar entry is a directory, does not have a CRC"); \
@@ -4552,12 +4576,12 @@ PHP_METHOD(PharFileInfo, getCRC32)
/* {{{ Returns whether file entry is CRC checked */
PHP_METHOD(PharFileInfo, isCRCChecked)
{
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
RETURN_BOOL(entry_obj->entry->is_crc_checked);
}
/* }}} */
@@ -4565,12 +4589,12 @@ PHP_METHOD(PharFileInfo, isCRCChecked)
/* {{{ Returns the Phar file entry flags */
PHP_METHOD(PharFileInfo, getPharFlags)
{
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
RETURN_LONG(entry_obj->entry->flags & ~(PHAR_ENT_PERM_MASK|PHAR_ENT_COMPRESSION_MASK));
}
/* }}} */
@@ -4580,6 +4604,11 @@ PHP_METHOD(PharFileInfo, chmod)
{
char *error;
zend_long perms;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &perms) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ENTRY_OBJECT();
if (entry_obj->entry->is_temp_dir) {
@@ -4593,10 +4622,6 @@ PHP_METHOD(PharFileInfo, chmod)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &perms) == FAILURE) {
- RETURN_THROWS();
- }
-
if (entry_obj->entry->is_persistent) {
phar_archive_data *phar = entry_obj->entry->phar;
@@ -4639,12 +4664,12 @@ PHP_METHOD(PharFileInfo, chmod)
/* {{{ Returns the metadata of the entry */
PHP_METHOD(PharFileInfo, hasMetadata)
{
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
RETURN_BOOL(phar_metadata_tracker_has_data(&entry_obj->entry->metadata_tracker, entry_obj->entry->is_persistent));
}
/* }}} */
@@ -4654,13 +4679,14 @@ PHP_METHOD(PharFileInfo, getMetadata)
{
HashTable *unserialize_options = NULL;
phar_metadata_tracker *tracker;
- PHAR_ENTRY_OBJECT();
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ARRAY_HT(unserialize_options)
ZEND_PARSE_PARAMETERS_END();
+ PHAR_ENTRY_OBJECT();
+
tracker = &entry_obj->entry->metadata_tracker;
if (phar_metadata_tracker_has_data(tracker, entry_obj->entry->is_persistent)) {
phar_metadata_tracker_unserialize_or_copy(tracker, return_value, entry_obj->entry->is_persistent, unserialize_options, "PharFileInfo::getMetadata");
@@ -4674,6 +4700,10 @@ PHP_METHOD(PharFileInfo, setMetadata)
char *error;
zval *metadata;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &metadata) == FAILURE) {
+ RETURN_THROWS();
+ }
+
PHAR_ENTRY_OBJECT();
if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) {
@@ -4687,10 +4717,6 @@ PHP_METHOD(PharFileInfo, setMetadata)
RETURN_THROWS();
}
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &metadata) == FAILURE) {
- RETURN_THROWS();
- }
-
if (entry_obj->entry->is_persistent) {
phar_archive_data *phar = entry_obj->entry->phar;
@@ -4723,12 +4749,12 @@ PHP_METHOD(PharFileInfo, delMetadata)
{
char *error;
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly");
RETURN_THROWS();
@@ -4780,12 +4806,12 @@ PHP_METHOD(PharFileInfo, getContent)
phar_entry_info *link;
zend_string *str;
- PHAR_ENTRY_OBJECT();
-
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
if (entry_obj->entry->is_dir) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
"phar error: Cannot retrieve contents, \"%s\" in phar \"%s\" is a directory", entry_obj->entry->filename, entry_obj->entry->phar->fname);
@@ -4826,12 +4852,13 @@ PHP_METHOD(PharFileInfo, compress)
{
zend_long method;
char *error;
- PHAR_ENTRY_OBJECT();
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &method) == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
if (entry_obj->entry->is_tar) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
"Cannot compress with Gzip compression, not possible with tar-based phar archives");
@@ -4952,12 +4979,13 @@ PHP_METHOD(PharFileInfo, decompress)
{
char *error;
char *compression_type;
- PHAR_ENTRY_OBJECT();
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
+ PHAR_ENTRY_OBJECT();
+
if (entry_obj->entry->is_dir) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \
"Phar entry is a directory, cannot set compression"); \