diff options
Diffstat (limited to 'ext/zip/php_zip.c')
-rw-r--r-- | ext/zip/php_zip.c | 408 |
1 files changed, 127 insertions, 281 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 4fedabad1c..71edbe10b9 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2018 The PHP Group | + | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | 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 | @@ -28,11 +28,7 @@ #include "ext/standard/php_string.h" #include "ext/pcre/php_pcre.h" #include "ext/standard/php_filestat.h" -#if PHP_VERSION_ID >= 70200 #include "zend_interfaces.h" -#elif defined(HAVE_SPL) -#include "ext/spl/spl_iterators.h" -#endif #include "php_zip.h" /* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */ @@ -84,10 +80,10 @@ static int le_zip_entry; #define PHP_ZIP_SET_FILE_COMMENT(za, index, comment, comment_len) \ if (comment_len == 0) { \ /* Passing NULL remove the existing comment */ \ - if (zip_set_file_comment(za, index, NULL, 0) < 0) { \ + if (zip_file_set_comment(za, index, NULL, 0, 0) < 0) { \ RETURN_FALSE; \ } \ - } else if (zip_set_file_comment(za, index, comment, comment_len) < 0) { \ + } else if (zip_file_set_comment(za, index, comment, comment_len, 0) < 0) { \ RETURN_FALSE; \ } \ RETURN_TRUE; @@ -412,7 +408,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char #endif /* }}} */ -static int php_zip_status(struct zip *za) /* {{{ */ +static zend_long php_zip_status(struct zip *za) /* {{{ */ { #if LIBZIP_VERSION_MAJOR < 1 int zep, syp; @@ -430,7 +426,7 @@ static int php_zip_status(struct zip *za) /* {{{ */ } /* }}} */ -static int php_zip_status_sys(struct zip *za) /* {{{ */ +static zend_long php_zip_status_sys(struct zip *za) /* {{{ */ { #if LIBZIP_VERSION_MAJOR < 1 int zep, syp; @@ -448,9 +444,10 @@ static int php_zip_status_sys(struct zip *za) /* {{{ */ } /* }}} */ -static int php_zip_get_num_files(struct zip *za) /* {{{ */ +static zend_long php_zip_get_num_files(struct zip *za) /* {{{ */ { - return zip_get_num_files(za); + zip_int64_t num = zip_get_num_entries(za, 0); + return MIN(num, ZEND_LONG_MAX); } /* }}} */ @@ -619,7 +616,6 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val { #ifdef ZTS char cwd[MAXPATHLEN]; - int cwd_skip = 0; char work_path[MAXPATHLEN]; char *result; #endif @@ -638,8 +634,6 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val cwd[2] = '\0'; } #endif - cwd_skip = strlen(cwd)+1; - snprintf(work_path, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, path); path = work_path; } @@ -654,10 +648,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val if (files_cnt > 0) { pcre2_code *re = NULL; pcre2_match_data *match_data = NULL; - uint32_t preg_options = 0, i, capture_count; + uint32_t i, capture_count; int rc; - re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options); + re = pcre_get_compiled_regex(regexp, &capture_count); if (!re) { php_error_docref(NULL, E_WARNING, "Invalid expression"); return -1; @@ -684,29 +678,29 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val break; } - snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, ZSTR_VAL(namelist[i])); - - if (0 != VCWD_STAT(fullpath, &s)) { - php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath); + match_data = php_pcre_create_match_data(capture_count, re); + if (!match_data) { + /* Allocation failed, but can proceed to the next pattern. */ zend_string_release_ex(namelist[i], 0); continue; } - - if (S_IFDIR == (s.st_mode & S_IFMT)) { + rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, 0, match_data, mctx); + php_pcre_free_match_data(match_data); + /* 0 means that the vector is too small to hold all the captured substring offsets */ + if (rc < 0) { zend_string_release_ex(namelist[i], 0); continue; } - match_data = php_pcre_create_match_data(capture_count, re); - if (!match_data) { - /* Allocation failed, but can proceed to the next pattern. */ + snprintf(fullpath, MAXPATHLEN, "%s%c%s", path, DEFAULT_SLASH, ZSTR_VAL(namelist[i])); + + if (0 != VCWD_STAT(fullpath, &s)) { + php_error_docref(NULL, E_WARNING, "Cannot read <%s>", fullpath); zend_string_release_ex(namelist[i], 0); continue; } - rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, preg_options, match_data, mctx); - php_pcre_free_match_data(match_data); - /* 0 means that the vector is too small to hold all the captured substring offsets */ - if (rc < 0) { + + if (S_IFDIR == (s.st_mode & S_IFMT)) { zend_string_release_ex(namelist[i], 0); continue; } @@ -791,7 +785,7 @@ static zend_object_handlers zip_object_handlers; static HashTable zip_prop_handlers; -typedef int (*zip_read_int_t)(struct zip *za); +typedef zend_long (*zip_read_int_t)(struct zip *za); typedef char *(*zip_read_const_char_t)(struct zip *za, int *len); typedef char *(*zip_read_const_char_from_ze_t)(ze_zip_object *obj); @@ -827,7 +821,7 @@ static void php_zip_register_prop_handler(HashTable *prop_handler, char *name, z static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, zval *rv) /* {{{ */ { const char *retchar = NULL; - int retint = 0; + zend_long retint = 0; int len = 0; if (obj && obj->za != NULL) { @@ -859,10 +853,10 @@ static zval *php_zip_property_reader(ze_zip_object *obj, zip_prop_handler *hnd, break; /* case IS_TRUE */ case IS_FALSE: - ZVAL_BOOL(rv, (long)retint); + ZVAL_BOOL(rv, retint); break; case IS_LONG: - ZVAL_LONG(rv, (long)retint); + ZVAL_LONG(rv, retint); break; default: ZVAL_NULL(rv); @@ -880,7 +874,11 @@ static zval *php_zip_get_property_ptr_ptr(zval *object, zval *member, int type, zip_prop_handler *hnd = NULL; if (Z_TYPE_P(member) != IS_STRING) { - ZVAL_STR(&tmp_member, zval_get_string_func(member)); + zend_string *str = zval_try_get_string_func(member); + if (UNEXPECTED(!str)) { + return NULL; + } + ZVAL_STR(&tmp_member, str); member = &tmp_member; cache_slot = NULL; } @@ -911,7 +909,11 @@ static zval *php_zip_read_property(zval *object, zval *member, int type, void ** zip_prop_handler *hnd = NULL; if (Z_TYPE_P(member) != IS_STRING) { - ZVAL_STR(&tmp_member, zval_get_string_func(member)); + zend_string *str = zval_try_get_string_func(member); + if (UNEXPECTED(!str)) { + return &EG(uninitialized_zval); + } + ZVAL_STR(&tmp_member, str); member = &tmp_member; cache_slot = NULL; } @@ -947,7 +949,11 @@ static int php_zip_has_property(zval *object, zval *member, int type, void **cac int retval = 0; if (Z_TYPE_P(member) != IS_STRING) { - ZVAL_STR(&tmp_member, zval_get_string_func(member)); + zend_string *str = zval_try_get_string_func(member); + if (UNEXPECTED(!str)) { + return 0; + } + ZVAL_STR(&tmp_member, str); member = &tmp_member; cache_slot = NULL; } @@ -1030,7 +1036,7 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */ if (intern->za) { if (zip_close(intern->za) != 0) { #if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1 - php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", "zip_close have failed"); + php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: zip_close have failed"); #else php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(intern->za)); zip_discard(intern->za); @@ -1172,7 +1178,7 @@ static PHP_NAMED_FUNCTION(zif_zip_open) } rsrc_int->index_current = 0; - rsrc_int->num_files = zip_get_num_files(rsrc_int->za); + rsrc_int->num_files = zip_get_num_entries(rsrc_int->za, 0); RETURN_RES(zend_register_resource(rsrc_int, le_zip_dir)); } @@ -1354,47 +1360,36 @@ static void php_zip_entry_get_info(INTERNAL_FUNCTION_PARAMETERS, int opt) /* {{{ switch (opt) { case 0: RETURN_STRING((char *)zr_rsrc->sb.name); - break; case 1: RETURN_LONG((zend_long) (zr_rsrc->sb.comp_size)); - break; case 2: RETURN_LONG((zend_long) (zr_rsrc->sb.size)); - break; case 3: switch (zr_rsrc->sb.comp_method) { case 0: RETURN_STRING("stored"); - break; case 1: RETURN_STRING("shrunk"); - break; case 2: case 3: case 4: case 5: RETURN_STRING("reduced"); - break; case 6: RETURN_STRING("imploded"); - break; case 7: RETURN_STRING("tokenized"); break; case 8: RETURN_STRING("deflated"); - break; case 9: RETURN_STRING("deflatedX"); break; case 10: RETURN_STRING("implodedX"); - break; default: RETURN_FALSE; } - RETURN_LONG((zend_long) (zr_rsrc->sb.comp_method)); - break; } } @@ -1441,17 +1436,15 @@ static ZIPARCHIVE_METHOD(open) zend_long flags = 0; char *resolved_path; zend_string *filename; - zval *self = getThis(); - ze_zip_object *ze_obj = NULL; + zval *self = ZEND_THIS; + ze_zip_object *ze_obj; if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &filename, &flags) == FAILURE) { return; } - if (self) { - /* We do not use ZIP_FROM_OBJECT, zip init function here */ - ze_obj = Z_ZIP_P(self); - } + /* We do not use ZIP_FROM_OBJECT, zip init function here */ + ze_obj = Z_ZIP_P(self); if (ZSTR_LEN(filename) == 0) { php_error_docref(NULL, E_WARNING, "Empty string as source"); @@ -1497,14 +1490,10 @@ Set the password for the active archive */ static ZIPARCHIVE_METHOD(setPassword) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; char *password; size_t password_len; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) { @@ -1529,21 +1518,17 @@ close the zip archive */ static ZIPARCHIVE_METHOD(close) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; ze_zip_object *ze_obj; int err; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); ze_obj = Z_ZIP_P(self); if ((err = zip_close(intern))) { #if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO == 1 - php_error_docref(NULL, E_WARNING, "%s", "zip_close have failed"); + php_error_docref(NULL, E_WARNING, "zip_close have failed"); #else php_error_docref(NULL, E_WARNING, "%s", zip_strerror(intern)); zip_discard(intern); @@ -1568,15 +1553,13 @@ close the zip archive */ static ZIPARCHIVE_METHOD(count) { struct zip *intern; - zval *self = getThis(); - - if (!self) { - RETURN_FALSE; - } + zval *self = ZEND_THIS; + zip_int64_t num; ZIP_FROM_OBJECT(intern, self); - RETVAL_LONG(zip_get_num_files(intern)); + num = zip_get_num_entries(intern, 0); + RETVAL_LONG(MIN(num, ZEND_LONG_MAX)); } /* }}} */ @@ -1585,7 +1568,7 @@ static ZIPARCHIVE_METHOD(count) static ZIPARCHIVE_METHOD(getStatusString) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; #if LIBZIP_VERSION_MAJOR < 1 int zep, syp, len; char error_string[128]; @@ -1593,10 +1576,6 @@ static ZIPARCHIVE_METHOD(getStatusString) zip_error_t *err; #endif - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); #if LIBZIP_VERSION_MAJOR < 1 @@ -1617,17 +1596,13 @@ Returns the index of the entry named filename in the archive */ static ZIPARCHIVE_METHOD(addEmptyDir) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; char *dirname; size_t dirname_len; int idx; struct zip_stat sb; char *s; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", @@ -1668,7 +1643,7 @@ static ZIPARCHIVE_METHOD(addEmptyDir) static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; char *path = "."; char *remove_path = NULL; char *add_path = NULL; @@ -1679,10 +1654,6 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* int found; zend_string *pattern; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); /* 1 == glob, 2 == pcre */ if (type == 1) { @@ -1793,16 +1764,12 @@ Add a file in a Zip archive using its path and the name to use. */ static ZIPARCHIVE_METHOD(addFile) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; char *entry_name = NULL; size_t entry_name_len = 0; zend_long offset_start = 0, offset_len = 0; zend_string *filename; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|sll", @@ -1833,7 +1800,7 @@ Add a file using content and the entry name */ static ZIPARCHIVE_METHOD(addFromString) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_string *buffer; char *name; size_t name_len; @@ -1842,10 +1809,6 @@ static ZIPARCHIVE_METHOD(addFromString) int pos = 0; int cur_idx; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS", @@ -1880,7 +1843,7 @@ static ZIPARCHIVE_METHOD(addFromString) } } - if (zip_add(intern, name, zs) == -1) { + if (zip_file_add(intern, name, zs, 0) == -1) { zip_source_free(zs); RETURN_FALSE; } else { @@ -1895,15 +1858,11 @@ Returns the information about a the zip entry filename */ static ZIPARCHIVE_METHOD(statName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long flags = 0; struct zip_stat sb; zend_string *name; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) { @@ -1917,19 +1876,15 @@ static ZIPARCHIVE_METHOD(statName) /* }}} */ /* {{{ proto resource ZipArchive::statIndex(int index[, int flags]) -Returns the zip entry informations using its index */ +Returns the zip entry information using its index */ static ZIPARCHIVE_METHOD(statIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index, flags = 0; struct zip_stat sb; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", @@ -1949,15 +1904,11 @@ Returns the index of the entry named filename in the archive */ static ZIPARCHIVE_METHOD(locateName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long flags = 0; zend_long idx = -1; zend_string *name; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) { @@ -1983,14 +1934,10 @@ Returns the name of the file at position index */ static ZIPARCHIVE_METHOD(getNameIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; const char *name; zend_long flags = 0, index = 0; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", @@ -2013,20 +1960,22 @@ Set or remove (NULL/'') the comment of the archive */ static ZIPARCHIVE_METHOD(setArchiveComment) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; size_t comment_len; char * comment; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &comment, &comment_len) == FAILURE) { return; } - if (zip_set_archive_comment(intern, (const char *)comment, (int)comment_len)) { + + if (comment_len > 0xffff) { + php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); + RETURN_FALSE; + } + + if (zip_set_archive_comment(intern, (const char *)comment, comment_len)) { RETURN_FALSE; } else { RETURN_TRUE; @@ -2039,15 +1988,11 @@ Returns the comment of an entry using its index */ static ZIPARCHIVE_METHOD(getArchiveComment) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long flags = 0; const char * comment; int comment_len = 0; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { @@ -2067,15 +2012,11 @@ Set or remove (NULL/'') the comment of an entry using its Name */ static ZIPARCHIVE_METHOD(setCommentName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; size_t comment_len, name_len; char * comment, *name; int idx; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", @@ -2087,6 +2028,11 @@ static ZIPARCHIVE_METHOD(setCommentName) php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } + if (comment_len > 0xffff) { + php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); + RETURN_FALSE; + } + idx = zip_name_locate(intern, name, 0); if (idx < 0) { RETURN_FALSE; @@ -2100,16 +2046,12 @@ Set or remove (NULL/'') the comment of an entry using its index */ static ZIPARCHIVE_METHOD(setCommentIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index; size_t comment_len; char * comment; struct zip_stat sb; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", @@ -2117,6 +2059,11 @@ static ZIPARCHIVE_METHOD(setCommentIndex) return; } + if (comment_len > 0xffff) { + php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); + RETURN_FALSE; + } + PHP_ZIP_STAT_INDEX(intern, index, 0, sb); PHP_ZIP_SET_FILE_COMMENT(intern, index, comment, comment_len); } @@ -2130,16 +2077,12 @@ Set external attributes for file in zip, using its name */ static ZIPARCHIVE_METHOD(setExternalAttributesName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; size_t name_len; char *name; zend_long flags=0, opsys, attr; zip_int64_t idx; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|l", @@ -2168,14 +2111,10 @@ Set external attributes for file in zip, using its index */ static ZIPARCHIVE_METHOD(setExternalAttributesIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index, flags=0, opsys, attr; struct zip_stat sb; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|l", @@ -2197,7 +2136,7 @@ Get external attributes for file in zip, using its name */ static ZIPARCHIVE_METHOD(getExternalAttributesName) { struct zip *intern; - zval *self = getThis(), *z_opsys, *z_attr; + zval *self = ZEND_THIS, *z_opsys, *z_attr; size_t name_len; char *name; zend_long flags=0; @@ -2205,13 +2144,9 @@ static ZIPARCHIVE_METHOD(getExternalAttributesName) zip_uint32_t attr; zip_int64_t idx; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz/z/|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "szz|l", &name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) { return; } @@ -2228,10 +2163,8 @@ static ZIPARCHIVE_METHOD(getExternalAttributesName) (zip_flags_t)flags, &opsys, &attr) < 0) { RETURN_FALSE; } - zval_ptr_dtor(z_opsys); - ZVAL_LONG(z_opsys, opsys); - zval_ptr_dtor(z_attr); - ZVAL_LONG(z_attr, attr); + ZEND_TRY_ASSIGN_REF_LONG(z_opsys, opsys); + ZEND_TRY_ASSIGN_REF_LONG(z_attr, attr); RETURN_TRUE; } /* }}} */ @@ -2241,19 +2174,15 @@ Get external attributes for file in zip, using its index */ static ZIPARCHIVE_METHOD(getExternalAttributesIndex) { struct zip *intern; - zval *self = getThis(), *z_opsys, *z_attr; + zval *self = ZEND_THIS, *z_opsys, *z_attr; zend_long index, flags=0; zip_uint8_t opsys; zip_uint32_t attr; struct zip_stat sb; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz/z/|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lzz|l", &index, &z_opsys, &z_attr, &flags) == FAILURE) { return; } @@ -2263,10 +2192,8 @@ static ZIPARCHIVE_METHOD(getExternalAttributesIndex) (zip_flags_t)flags, &opsys, &attr) < 0) { RETURN_FALSE; } - zval_ptr_dtor(z_opsys); - ZVAL_LONG(z_opsys, opsys); - zval_ptr_dtor(z_attr); - ZVAL_LONG(z_attr, attr); + ZEND_TRY_ASSIGN_REF_LONG(z_opsys, opsys); + ZEND_TRY_ASSIGN_REF_LONG(z_attr, attr); RETURN_TRUE; } /* }}} */ @@ -2278,16 +2205,12 @@ Set encryption method for file in zip, using its name */ static ZIPARCHIVE_METHOD(setEncryptionName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long method; zip_int64_t idx; char *name, *password = NULL; size_t name_len, password_len; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s", @@ -2316,15 +2239,11 @@ Set encryption method for file in zip, using its index */ static ZIPARCHIVE_METHOD(setEncryptionIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index, method; char *password = NULL; size_t password_len; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s", @@ -2345,18 +2264,14 @@ Returns the comment of an entry using its name */ static ZIPARCHIVE_METHOD(getCommentName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; size_t name_len; int idx; zend_long flags = 0; - int comment_len = 0; + zip_uint32_t comment_len = 0; const char * comment; char *name; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", @@ -2373,8 +2288,8 @@ static ZIPARCHIVE_METHOD(getCommentName) RETURN_FALSE; } - comment = zip_get_file_comment(intern, idx, &comment_len, (int)flags); - RETURN_STRINGL((char *)comment, (zend_long)comment_len); + comment = zip_file_get_comment(intern, idx, &comment_len, (zip_flags_t)flags); + RETURN_STRINGL((char *)comment, comment_len); } /* }}} */ @@ -2383,16 +2298,12 @@ Returns the comment of an entry using its index */ static ZIPARCHIVE_METHOD(getCommentIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index, flags = 0; const char * comment; - int comment_len = 0; + zip_uint32_t comment_len = 0; struct zip_stat sb; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", @@ -2401,8 +2312,8 @@ static ZIPARCHIVE_METHOD(getCommentIndex) } PHP_ZIP_STAT_INDEX(intern, index, 0, sb); - comment = zip_get_file_comment(intern, index, &comment_len, (int)flags); - RETURN_STRINGL((char *)comment, (zend_long)comment_len); + comment = zip_file_get_comment(intern, index, &comment_len, (zip_flags_t)flags); + RETURN_STRINGL((char *)comment, comment_len); } /* }}} */ @@ -2411,16 +2322,12 @@ Set the compression of a file in zip, using its name */ static ZIPARCHIVE_METHOD(setCompressionName) { struct zip *intern; - zval *this = getThis(); + zval *this = ZEND_THIS; size_t name_len; char *name; zip_int64_t idx; zend_long comp_method, comp_flags = 0; - if (!this) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, this); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l", @@ -2450,14 +2357,10 @@ Set the compression of a file in zip, using its index */ static ZIPARCHIVE_METHOD(setCompressionIndex) { struct zip *intern; - zval *this = getThis(); + zval *this = ZEND_THIS; zend_long index; zend_long comp_method, comp_flags = 0; - if (!this) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, this); if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l", @@ -2478,13 +2381,9 @@ Delete a file using its index */ static ZIPARCHIVE_METHOD(deleteIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { @@ -2508,15 +2407,11 @@ Delete a file using its index */ static ZIPARCHIVE_METHOD(deleteName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; size_t name_len; char *name; struct zip_stat sb; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { @@ -2539,15 +2434,11 @@ Rename an entry selected by its index to new_name */ static ZIPARCHIVE_METHOD(renameIndex) { struct zip *intern; - zval *self = getThis(); - + zval *self = ZEND_THIS; char *new_name; size_t new_name_len; zend_long index; - if (!self) { - RETURN_FALSE; - } ZIP_FROM_OBJECT(intern, self); @@ -2563,7 +2454,7 @@ static ZIPARCHIVE_METHOD(renameIndex) php_error_docref(NULL, E_NOTICE, "Empty string as new entry name"); RETURN_FALSE; } - if (zip_rename(intern, index, (const char *)new_name) != 0) { + if (zip_file_rename(intern, index, (const char *)new_name, 0) != 0) { RETURN_FALSE; } RETURN_TRUE; @@ -2575,15 +2466,11 @@ Rename an entry selected by its name to new_name */ static ZIPARCHIVE_METHOD(renameName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; struct zip_stat sb; char *name, *new_name; size_t name_len, new_name_len; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &new_name, &new_name_len) == FAILURE) { @@ -2597,7 +2484,7 @@ static ZIPARCHIVE_METHOD(renameName) PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb); - if (zip_rename(intern, sb.index, (const char *)new_name)) { + if (zip_file_rename(intern, sb.index, (const char *)new_name, 0)) { RETURN_FALSE; } RETURN_TRUE; @@ -2609,13 +2496,9 @@ Changes to the file at position index are reverted */ static ZIPARCHIVE_METHOD(unchangeIndex) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zend_long index; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { @@ -2639,15 +2522,11 @@ Changes to the file named 'name' are reverted */ static ZIPARCHIVE_METHOD(unchangeName) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; struct zip_stat sb; char *name; size_t name_len; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { @@ -2673,11 +2552,7 @@ All changes to files and global information in archive are reverted */ static ZIPARCHIVE_METHOD(unchangeAll) { struct zip *intern; - zval *self = getThis(); - - if (!self) { - RETURN_FALSE; - } + zval *self = ZEND_THIS; ZIP_FROM_OBJECT(intern, self); @@ -2694,11 +2569,7 @@ Revert all global changes to the archive archive. For now, this only reverts ar static ZIPARCHIVE_METHOD(unchangeArchive) { struct zip *intern; - zval *self = getThis(); - - if (!self) { - RETURN_FALSE; - } + zval *self = ZEND_THIS; ZIP_FROM_OBJECT(intern, self); @@ -2713,7 +2584,7 @@ static ZIPARCHIVE_METHOD(unchangeArchive) /* {{{ proto bool ZipArchive::extractTo(string pathto[, mixed files]) Extract one or more file from a zip archive */ /* TODO: - * - allow index or array of indeces + * - allow index or array of indices * - replace path * - patterns */ @@ -2721,19 +2592,13 @@ static ZIPARCHIVE_METHOD(extractTo) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; zval *zval_files = NULL; zval *zval_file = NULL; php_stream_statbuf ssb; char *pathto; size_t pathto_len; - int ret, i; - - int nelems; - - if (!self) { - RETURN_FALSE; - } + int ret; if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|z", &pathto, &pathto_len, &zval_files) == FAILURE) { return; @@ -2752,6 +2617,8 @@ static ZIPARCHIVE_METHOD(extractTo) ZIP_FROM_OBJECT(intern, self); if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) { + uint32_t nelems, i; + switch (Z_TYPE_P(zval_files)) { case IS_STRING: if (!php_zip_extract_file(intern, pathto, Z_STRVAL_P(zval_files), Z_STRLEN_P(zval_files))) { @@ -2784,7 +2651,7 @@ static ZIPARCHIVE_METHOD(extractTo) } } else { /* Extract all files */ - int filecount = zip_get_num_files(intern); + zip_int64_t i, filecount = zip_get_num_entries(intern, 0); if (filecount == -1) { php_error_docref(NULL, E_WARNING, "Illegal archive"); @@ -2805,7 +2672,7 @@ static ZIPARCHIVE_METHOD(extractTo) static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; struct zip_stat sb; struct zip_file *zf; @@ -2819,10 +2686,6 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ int n = 0; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (type == 1) { @@ -2889,17 +2752,13 @@ get a stream for an entry using its name */ static ZIPARCHIVE_METHOD(getStream) { struct zip *intern; - zval *self = getThis(); + zval *self = ZEND_THIS; struct zip_stat sb; char *mode = "rb"; zend_string *filename; php_stream *stream; ze_zip_object *obj; - if (!self) { - RETURN_FALSE; - } - ZIP_FROM_OBJECT(intern, self); if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) { @@ -3174,11 +3033,7 @@ static PHP_MINIT_FUNCTION(zip) php_zip_register_prop_handler(&zip_prop_handlers, "numFiles", php_zip_get_num_files, NULL, NULL, IS_LONG); php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, NULL, php_zipobj_get_filename, IS_STRING); php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, NULL, IS_STRING); -#if PHP_VERSION_ID >= 70200 zend_class_implements(zip_class_entry, 1, zend_ce_countable); -#elif defined(HAVE_SPL) - zend_class_implements(zip_class_entry, 1, spl_ce_Countable); -#endif REGISTER_ZIP_CLASS_CONST_LONG("CREATE", ZIP_CREATE); REGISTER_ZIP_CLASS_CONST_LONG("EXCL", ZIP_EXCL); @@ -3321,12 +3176,3 @@ static PHP_MINFO_FUNCTION(zip) php_info_print_table_end(); } /* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ |