]> granicus.if.org Git - php/commitdiff
Fix ZPP order in ext/zip
authorMáté Kocsis <kocsismate@woohoolabs.com>
Sun, 3 May 2020 09:41:32 +0000 (11:41 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 6 May 2020 17:14:36 +0000 (19:14 +0200)
ext/zip/php_zip.c

index 3b9b07097e50b8e41234bd50cd189b360724dfb8..2d3b3c3107ca3f02e54d12b15132142ceaf51b0a 100644 (file)
@@ -1519,21 +1519,21 @@ static ZIPARCHIVE_METHOD(setPassword)
        char *password;
        size_t  password_len;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (password_len < 1) {
                RETURN_FALSE;
+       }
+
+       int res = zip_set_default_password(intern, (const char *)password);
+       if (res == 0) {
+               RETURN_TRUE;
        } else {
-               int res = zip_set_default_password(intern, (const char *)password);
-               if (res == 0) {
-                       RETURN_TRUE;
-               } else {
-                       RETURN_FALSE;
-               }
+               RETURN_FALSE;
        }
 }
 /* }}} */
@@ -1664,13 +1664,13 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
        char *s;
        zend_long flags = 0;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l",
                                &dirname, &dirname_len, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (dirname_len<1) {
                RETURN_FALSE;
        }
@@ -1725,7 +1725,6 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
                php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
                RETURN_FALSE;
        }
-       if (options && (php_zip_parse_options(options, &opts) < 0)) {
                RETURN_FALSE;
        }
 
@@ -1909,13 +1908,13 @@ static ZIPARCHIVE_METHOD(addFromString)
        int pos = 0;
        zend_long flags = ZIP_FL_OVERWRITE;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS|l",
                        &name, &name_len, &buffer, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        ze_obj = Z_ZIP_P(self);
        if (ze_obj->buffers_cnt) {
                ze_obj->buffers = (char **)safe_erealloc(ze_obj->buffers, sizeof(char *), (ze_obj->buffers_cnt+1), 0);
@@ -1955,12 +1954,12 @@ static ZIPARCHIVE_METHOD(statName)
        struct zip_stat sb;
        zend_string *name;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        PHP_ZIP_STAT_PATH(intern, ZSTR_VAL(name), ZSTR_LEN(name), flags, sb);
 
        RETURN_SB(&sb);
@@ -1977,13 +1976,13 @@ static ZIPARCHIVE_METHOD(statIndex)
 
        struct zip_stat sb;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
                        &index, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (zip_stat_index(intern, index, flags, &sb) != 0) {
                RETURN_FALSE;
        }
@@ -2001,12 +2000,12 @@ static ZIPARCHIVE_METHOD(locateName)
        zend_long idx = -1;
        zend_string *name;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (ZSTR_LEN(name) < 1) {
                RETURN_FALSE;
        }
@@ -2030,13 +2029,13 @@ static ZIPARCHIVE_METHOD(getNameIndex)
        const char *name;
        zend_long flags = 0, index = 0;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
                        &index, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        name = zip_get_name(intern, (int) index, flags);
 
        if (name) {
@@ -2056,12 +2055,12 @@ static ZIPARCHIVE_METHOD(setArchiveComment)
        size_t comment_len;
        char * comment;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &comment, &comment_len) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (comment_len > 0xffff) {
                php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes");
                RETURN_FALSE;
@@ -2085,12 +2084,12 @@ static ZIPARCHIVE_METHOD(getArchiveComment)
        const char * comment;
        int comment_len = 0;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        comment = zip_get_archive_comment(intern, &comment_len, (int)flags);
        if(comment==NULL) {
                RETURN_FALSE;
@@ -2109,8 +2108,6 @@ static ZIPARCHIVE_METHOD(setCommentName)
        char * comment, *name;
        int idx;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss",
                        &name, &name_len, &comment, &comment_len) == FAILURE) {
                RETURN_THROWS();
@@ -2120,6 +2117,8 @@ static ZIPARCHIVE_METHOD(setCommentName)
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (comment_len > 0xffff) {
                php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes");
                RETURN_FALSE;
@@ -2144,13 +2143,13 @@ static ZIPARCHIVE_METHOD(setCommentIndex)
        char * comment;
        struct zip_stat sb;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls",
                        &index, &comment, &comment_len) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (comment_len > 0xffff) {
                php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes");
                RETURN_FALSE;
@@ -2175,13 +2174,13 @@ static ZIPARCHIVE_METHOD(setExternalAttributesName)
        zend_long flags=0, opsys, attr;
        zip_int64_t idx;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|l",
                        &name, &name_len, &opsys, &attr, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
        }
@@ -2207,13 +2206,13 @@ static ZIPARCHIVE_METHOD(setExternalAttributesIndex)
        zend_long index, flags=0, opsys, attr;
        struct zip_stat sb;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|l",
                        &index, &opsys, &attr, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
        if (zip_file_set_external_attributes(intern, (zip_uint64_t)index,
                        (zip_flags_t)flags, (zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) {
@@ -2236,13 +2235,13 @@ static ZIPARCHIVE_METHOD(getExternalAttributesName)
        zip_uint32_t attr;
        zip_int64_t idx;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "szz|l",
                        &name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
        }
@@ -2272,13 +2271,13 @@ static ZIPARCHIVE_METHOD(getExternalAttributesIndex)
        zip_uint32_t attr;
        struct zip_stat sb;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "lzz|l",
                        &index, &z_opsys, &z_attr, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
        if (zip_file_get_external_attributes(intern, (zip_uint64_t)index,
                        (zip_flags_t)flags, &opsys, &attr) < 0) {
@@ -2310,6 +2309,8 @@ static ZIPARCHIVE_METHOD(setEncryptionName)
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
        }
@@ -2336,7 +2337,6 @@ static ZIPARCHIVE_METHOD(setEncryptionIndex)
        char *password = NULL;
        size_t password_len;
 
-       ZIP_FROM_OBJECT(intern, self);
 
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s",
                        &index, &method, &password, &password_len) == FAILURE) {
@@ -2344,6 +2344,7 @@ static ZIPARCHIVE_METHOD(setEncryptionIndex)
        }
 
        if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
+       ZIP_FROM_OBJECT(intern, self);
                RETURN_FALSE;
        }
        RETURN_TRUE;
@@ -2364,12 +2365,13 @@ static ZIPARCHIVE_METHOD(getCommentName)
        const char * comment;
        char *name;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l",
                        &name, &name_len, &flags) == FAILURE) {
                RETURN_THROWS();
        }
+
+       ZIP_FROM_OBJECT(intern, self);
+
        if (name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
                RETURN_FALSE;
@@ -2396,13 +2398,13 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
        zip_uint32_t comment_len = 0;
        struct zip_stat sb;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l",
                                &index, &flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
        comment = zip_file_get_comment(intern, index, &comment_len, (zip_flags_t)flags);
        RETURN_STRINGL((char *)comment, comment_len);
@@ -2420,13 +2422,13 @@ static ZIPARCHIVE_METHOD(setCompressionName)
        zip_int64_t idx;
        zend_long comp_method, comp_flags = 0;
 
-       ZIP_FROM_OBJECT(intern, this);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l",
                        &name, &name_len, &comp_method, &comp_flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, this);
+
        if (name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
        }
@@ -2453,13 +2455,13 @@ static ZIPARCHIVE_METHOD(setCompressionIndex)
        zend_long index;
        zend_long comp_method, comp_flags = 0;
 
-       ZIP_FROM_OBJECT(intern, this);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l",
                        &index, &comp_method, &comp_flags) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, this);
+
        if (zip_set_file_compression(intern, (zip_uint64_t)index,
                        (zip_int32_t)comp_method, (zip_uint32_t)comp_flags) != 0) {
                RETURN_FALSE;
@@ -2480,13 +2482,13 @@ static ZIPARCHIVE_METHOD(setMtimeName)
        zip_int64_t idx;
        zend_long mtime, flags = 0;
 
-       ZIP_FROM_OBJECT(intern, this);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l",
                        &name, &name_len, &mtime,  &flags) == FAILURE) {
                return;
        }
 
+       ZIP_FROM_OBJECT(intern, this);
+
        if (name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as entry name");
        }
@@ -2513,13 +2515,13 @@ static ZIPARCHIVE_METHOD(setMtimeIndex)
        zend_long index;
        zend_long mtime, flags = 0;
 
-       ZIP_FROM_OBJECT(intern, this);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l",
                        &index, &mtime, &flags) == FAILURE) {
                return;
        }
 
+       ZIP_FROM_OBJECT(intern, this);
+
        if (zip_file_set_mtime(intern, (zip_uint64_t)index,
                        (time_t)mtime, (zip_uint32_t)flags) != 0) {
                RETURN_FALSE;
@@ -2537,12 +2539,12 @@ static ZIPARCHIVE_METHOD(deleteIndex)
        zval *self = ZEND_THIS;
        zend_long index;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (index < 0) {
                RETURN_FALSE;
        }
@@ -2565,11 +2567,12 @@ static ZIPARCHIVE_METHOD(deleteName)
        char *name;
        struct zip_stat sb;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
                RETURN_THROWS();
        }
+
+       ZIP_FROM_OBJECT(intern, self);
+
        if (name_len < 1) {
                RETURN_FALSE;
        }
@@ -2592,9 +2595,6 @@ static ZIPARCHIVE_METHOD(renameIndex)
        size_t new_name_len;
        zend_long index;
 
-
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &index, &new_name, &new_name_len) == FAILURE) {
                RETURN_THROWS();
        }
@@ -2603,13 +2603,17 @@ static ZIPARCHIVE_METHOD(renameIndex)
                RETURN_FALSE;
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (new_name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
                RETURN_FALSE;
        }
+
        if (zip_file_rename(intern, index, (const char *)new_name, 0) != 0) {
                RETURN_FALSE;
        }
+
        RETURN_TRUE;
 }
 /* }}} */
@@ -2624,12 +2628,12 @@ static ZIPARCHIVE_METHOD(renameName)
        char *name, *new_name;
        size_t name_len, new_name_len;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &new_name, &new_name_len) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (new_name_len < 1) {
                php_error_docref(NULL, E_NOTICE, "Empty string as new entry name");
                RETURN_FALSE;
@@ -2640,6 +2644,7 @@ static ZIPARCHIVE_METHOD(renameName)
        if (zip_file_rename(intern, sb.index, (const char *)new_name, 0)) {
                RETURN_FALSE;
        }
+
        RETURN_TRUE;
 }
 /* }}} */
@@ -2652,12 +2657,12 @@ static ZIPARCHIVE_METHOD(unchangeIndex)
        zval *self = ZEND_THIS;
        zend_long index;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (index < 0) {
                RETURN_FALSE;
        }
@@ -2680,12 +2685,12 @@ static ZIPARCHIVE_METHOD(unchangeName)
        char *name;
        size_t name_len;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (name_len < 1) {
                RETURN_FALSE;
        }
@@ -2761,10 +2766,11 @@ static ZIPARCHIVE_METHOD(extractTo)
        size_t pathto_len;
        int ret;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|z", &pathto, &pathto_len, &zval_files) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (pathto_len < 1) {
                RETURN_FALSE;
        }
@@ -2776,8 +2782,7 @@ static ZIPARCHIVE_METHOD(extractTo)
                        }
        }
 
-       ZIP_FROM_OBJECT(intern, self);
-       if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) {
+       if (zval_files && Z_TYPE_P(zval_files) != IS_NULL) {
                uint32_t nelems, i;
 
                switch (Z_TYPE_P(zval_files)) {
@@ -2847,17 +2852,21 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
 
        int n = 0;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (type == 1) {
                if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) {
                        RETURN_THROWS();
                }
+
+               ZIP_FROM_OBJECT(intern, self);
+
                PHP_ZIP_STAT_PATH(intern, ZSTR_VAL(filename), ZSTR_LEN(filename), flags, sb);
        } else {
                if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &index, &len, &flags) == FAILURE) {
                        RETURN_THROWS();
                }
+
+               ZIP_FROM_OBJECT(intern, self);
+
                PHP_ZIP_STAT_INDEX(intern, index, 0, sb);
        }
 
@@ -2920,12 +2929,12 @@ static ZIPARCHIVE_METHOD(getStream)
        php_stream *stream;
        ze_zip_object *obj;
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) {
                RETURN_THROWS();
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        if (zip_stat(intern, ZSTR_VAL(filename), 0, &sb) != 0) {
                RETURN_FALSE;
        }
@@ -2968,8 +2977,6 @@ static ZIPARCHIVE_METHOD(registerProgressCallback)
                RETURN_FALSE;
        }
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "dz", &rate, &callback) == FAILURE) {
                return;
        }
@@ -2982,6 +2989,8 @@ static ZIPARCHIVE_METHOD(registerProgressCallback)
                RETURN_FALSE;
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        obj = Z_ZIP_P(self);
 
        /* free if called twice */
@@ -3026,12 +3035,12 @@ static ZIPARCHIVE_METHOD(registerCancelCallback)
                RETURN_FALSE;
        }
 
-       ZIP_FROM_OBJECT(intern, self);
-
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback) == FAILURE) {
                return;
        }
 
+       ZIP_FROM_OBJECT(intern, self);
+
        /* callable? */
        if (!zend_is_callable(callback, 0, NULL)) {
                zend_string *callback_name = zend_get_callable_name(callback);