@@ -81,10 +81,10 @@ static int le_zip_entry;
81
81
#define PHP_ZIP_SET_FILE_COMMENT (za , index , comment , comment_len ) \
82
82
if (comment_len == 0) { \
83
83
/* Passing NULL remove the existing comment */ \
84
- if (zip_set_file_comment (za, index, NULL, 0) < 0) { \
84
+ if (zip_file_set_comment (za, index, NULL, 0 , 0) < 0) { \
85
85
RETURN_FALSE; \
86
86
} \
87
- } else if (zip_set_file_comment (za, index, comment, comment_len) < 0) { \
87
+ } else if (zip_file_set_comment (za, index, comment, comment_len, 0 ) < 0) { \
88
88
RETURN_FALSE; \
89
89
} \
90
90
RETURN_TRUE;
@@ -409,7 +409,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
409
409
#endif
410
410
/* }}} */
411
411
412
- static int php_zip_status (struct zip * za ) /* {{{ */
412
+ static zend_long php_zip_status (struct zip * za ) /* {{{ */
413
413
{
414
414
#if LIBZIP_VERSION_MAJOR < 1
415
415
int zep , syp ;
@@ -427,7 +427,7 @@ static int php_zip_status(struct zip *za) /* {{{ */
427
427
}
428
428
/* }}} */
429
429
430
- static int php_zip_status_sys (struct zip * za ) /* {{{ */
430
+ static zend_long php_zip_status_sys (struct zip * za ) /* {{{ */
431
431
{
432
432
#if LIBZIP_VERSION_MAJOR < 1
433
433
int zep , syp ;
@@ -445,9 +445,10 @@ static int php_zip_status_sys(struct zip *za) /* {{{ */
445
445
}
446
446
/* }}} */
447
447
448
- static int php_zip_get_num_files (struct zip * za ) /* {{{ */
448
+ static zend_long php_zip_get_num_files (struct zip * za ) /* {{{ */
449
449
{
450
- return zip_get_num_files (za );
450
+ zip_int64_t num = zip_get_num_entries (za , 0 );
451
+ return MIN (num , ZEND_LONG_MAX );
451
452
}
452
453
/* }}} */
453
454
@@ -740,7 +741,7 @@ static zend_object_handlers zip_object_handlers;
740
741
741
742
static HashTable zip_prop_handlers ;
742
743
743
- typedef int (* zip_read_int_t )(struct zip * za );
744
+ typedef zend_long (* zip_read_int_t )(struct zip * za );
744
745
typedef char * (* zip_read_const_char_t )(struct zip * za , int * len );
745
746
typedef char * (* zip_read_const_char_from_ze_t )(ze_zip_object * obj );
746
747
@@ -1088,7 +1089,7 @@ static PHP_NAMED_FUNCTION(zif_zip_open)
1088
1089
}
1089
1090
1090
1091
rsrc_int -> index_current = 0 ;
1091
- rsrc_int -> num_files = zip_get_num_files (rsrc_int -> za );
1092
+ rsrc_int -> num_files = zip_get_num_entries (rsrc_int -> za , 0 );
1092
1093
1093
1094
RETURN_RES (zend_register_resource (rsrc_int , le_zip_dir ));
1094
1095
}
@@ -1464,10 +1465,12 @@ static ZIPARCHIVE_METHOD(count)
1464
1465
{
1465
1466
struct zip * intern ;
1466
1467
zval * self = ZEND_THIS ;
1468
+ zip_int64_t num ;
1467
1469
1468
1470
ZIP_FROM_OBJECT (intern , self );
1469
1471
1470
- RETVAL_LONG (zip_get_num_files (intern ));
1472
+ num = zip_get_num_entries (intern , 0 );
1473
+ RETVAL_LONG (MIN (num , ZEND_LONG_MAX ));
1471
1474
}
1472
1475
/* }}} */
1473
1476
@@ -1751,7 +1754,7 @@ static ZIPARCHIVE_METHOD(addFromString)
1751
1754
}
1752
1755
}
1753
1756
1754
- if (zip_add (intern , name , zs ) == -1 ) {
1757
+ if (zip_file_add (intern , name , zs , 0 ) == -1 ) {
1755
1758
zip_source_free (zs );
1756
1759
RETURN_FALSE ;
1757
1760
} else {
@@ -1877,7 +1880,13 @@ static ZIPARCHIVE_METHOD(setArchiveComment)
1877
1880
if (zend_parse_parameters (ZEND_NUM_ARGS (), "s" , & comment , & comment_len ) == FAILURE ) {
1878
1881
return ;
1879
1882
}
1880
- if (zip_set_archive_comment (intern , (const char * )comment , (int )comment_len )) {
1883
+
1884
+ if (comment_len > 0xffff ) {
1885
+ php_error_docref (NULL , E_WARNING , "Comment must not exceed 65535 bytes" );
1886
+ RETURN_FALSE ;
1887
+ }
1888
+
1889
+ if (zip_set_archive_comment (intern , (const char * )comment , comment_len )) {
1881
1890
RETURN_FALSE ;
1882
1891
} else {
1883
1892
RETURN_TRUE ;
@@ -1930,6 +1939,11 @@ static ZIPARCHIVE_METHOD(setCommentName)
1930
1939
php_error_docref (NULL , E_NOTICE , "Empty string as entry name" );
1931
1940
}
1932
1941
1942
+ if (comment_len > 0xffff ) {
1943
+ php_error_docref (NULL , E_WARNING , "Comment must not exceed 65535 bytes" );
1944
+ RETURN_FALSE ;
1945
+ }
1946
+
1933
1947
idx = zip_name_locate (intern , name , 0 );
1934
1948
if (idx < 0 ) {
1935
1949
RETURN_FALSE ;
@@ -1956,6 +1970,11 @@ static ZIPARCHIVE_METHOD(setCommentIndex)
1956
1970
return ;
1957
1971
}
1958
1972
1973
+ if (comment_len > 0xffff ) {
1974
+ php_error_docref (NULL , E_WARNING , "Comment must not exceed 65535 bytes" );
1975
+ RETURN_FALSE ;
1976
+ }
1977
+
1959
1978
PHP_ZIP_STAT_INDEX (intern , index , 0 , sb );
1960
1979
PHP_ZIP_SET_FILE_COMMENT (intern , index , comment , comment_len );
1961
1980
}
@@ -2160,7 +2179,7 @@ static ZIPARCHIVE_METHOD(getCommentName)
2160
2179
size_t name_len ;
2161
2180
int idx ;
2162
2181
zend_long flags = 0 ;
2163
- int comment_len = 0 ;
2182
+ zip_uint32_t comment_len = 0 ;
2164
2183
const char * comment ;
2165
2184
char * name ;
2166
2185
@@ -2180,8 +2199,8 @@ static ZIPARCHIVE_METHOD(getCommentName)
2180
2199
RETURN_FALSE ;
2181
2200
}
2182
2201
2183
- comment = zip_get_file_comment (intern , idx , & comment_len , (int )flags );
2184
- RETURN_STRINGL ((char * )comment , ( zend_long ) comment_len );
2202
+ comment = zip_file_get_comment (intern , idx , & comment_len , (zip_flags_t )flags );
2203
+ RETURN_STRINGL ((char * )comment , comment_len );
2185
2204
}
2186
2205
/* }}} */
2187
2206
@@ -2193,7 +2212,7 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
2193
2212
zval * self = ZEND_THIS ;
2194
2213
zend_long index , flags = 0 ;
2195
2214
const char * comment ;
2196
- int comment_len = 0 ;
2215
+ zip_uint32_t comment_len = 0 ;
2197
2216
struct zip_stat sb ;
2198
2217
2199
2218
ZIP_FROM_OBJECT (intern , self );
@@ -2204,8 +2223,8 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
2204
2223
}
2205
2224
2206
2225
PHP_ZIP_STAT_INDEX (intern , index , 0 , sb );
2207
- comment = zip_get_file_comment (intern , index , & comment_len , (int )flags );
2208
- RETURN_STRINGL ((char * )comment , ( zend_long ) comment_len );
2226
+ comment = zip_file_get_comment (intern , index , & comment_len , (zip_flags_t )flags );
2227
+ RETURN_STRINGL ((char * )comment , comment_len );
2209
2228
}
2210
2229
/* }}} */
2211
2230
@@ -2346,7 +2365,7 @@ static ZIPARCHIVE_METHOD(renameIndex)
2346
2365
php_error_docref (NULL , E_NOTICE , "Empty string as new entry name" );
2347
2366
RETURN_FALSE ;
2348
2367
}
2349
- if (zip_rename (intern , index , (const char * )new_name ) != 0 ) {
2368
+ if (zip_file_rename (intern , index , (const char * )new_name , 0 ) != 0 ) {
2350
2369
RETURN_FALSE ;
2351
2370
}
2352
2371
RETURN_TRUE ;
@@ -2376,7 +2395,7 @@ static ZIPARCHIVE_METHOD(renameName)
2376
2395
2377
2396
PHP_ZIP_STAT_PATH (intern , name , name_len , 0 , sb );
2378
2397
2379
- if (zip_rename (intern , sb .index , (const char * )new_name )) {
2398
+ if (zip_file_rename (intern , sb .index , (const char * )new_name , 0 )) {
2380
2399
RETURN_FALSE ;
2381
2400
}
2382
2401
RETURN_TRUE ;
@@ -2490,9 +2509,7 @@ static ZIPARCHIVE_METHOD(extractTo)
2490
2509
php_stream_statbuf ssb ;
2491
2510
char * pathto ;
2492
2511
size_t pathto_len ;
2493
- int ret , i ;
2494
-
2495
- int nelems ;
2512
+ int ret ;
2496
2513
2497
2514
if (zend_parse_parameters (ZEND_NUM_ARGS (), "p|z" , & pathto , & pathto_len , & zval_files ) == FAILURE ) {
2498
2515
return ;
@@ -2511,6 +2528,8 @@ static ZIPARCHIVE_METHOD(extractTo)
2511
2528
2512
2529
ZIP_FROM_OBJECT (intern , self );
2513
2530
if (zval_files && (Z_TYPE_P (zval_files ) != IS_NULL )) {
2531
+ uint32_t nelems , i ;
2532
+
2514
2533
switch (Z_TYPE_P (zval_files )) {
2515
2534
case IS_STRING :
2516
2535
if (!php_zip_extract_file (intern , pathto , Z_STRVAL_P (zval_files ), Z_STRLEN_P (zval_files ))) {
@@ -2543,7 +2562,7 @@ static ZIPARCHIVE_METHOD(extractTo)
2543
2562
}
2544
2563
} else {
2545
2564
/* Extract all files */
2546
- int filecount = zip_get_num_files (intern );
2565
+ zip_int64_t i , filecount = zip_get_num_entries (intern , 0 );
2547
2566
2548
2567
if (filecount == -1 ) {
2549
2568
php_error_docref (NULL , E_WARNING , "Illegal archive" );
0 commit comments