@@ -80,10 +80,10 @@ static int le_zip_entry;
80
80
#define PHP_ZIP_SET_FILE_COMMENT (za , index , comment , comment_len ) \
81
81
if (comment_len == 0) { \
82
82
/* Passing NULL remove the existing comment */ \
83
- if (zip_set_file_comment (za, index, NULL, 0) < 0) { \
83
+ if (zip_file_set_comment (za, index, NULL, 0 , 0) < 0) { \
84
84
RETURN_FALSE; \
85
85
} \
86
- } else if (zip_set_file_comment (za, index, comment, comment_len) < 0) { \
86
+ } else if (zip_file_set_comment (za, index, comment, comment_len, 0 ) < 0) { \
87
87
RETURN_FALSE; \
88
88
} \
89
89
RETURN_TRUE;
@@ -408,7 +408,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char
408
408
#endif
409
409
/* }}} */
410
410
411
- static int php_zip_status (struct zip * za ) /* {{{ */
411
+ static zend_long php_zip_status (struct zip * za ) /* {{{ */
412
412
{
413
413
#if LIBZIP_VERSION_MAJOR < 1
414
414
int zep , syp ;
@@ -426,7 +426,7 @@ static int php_zip_status(struct zip *za) /* {{{ */
426
426
}
427
427
/* }}} */
428
428
429
- static int php_zip_status_sys (struct zip * za ) /* {{{ */
429
+ static zend_long php_zip_status_sys (struct zip * za ) /* {{{ */
430
430
{
431
431
#if LIBZIP_VERSION_MAJOR < 1
432
432
int zep , syp ;
@@ -444,9 +444,10 @@ static int php_zip_status_sys(struct zip *za) /* {{{ */
444
444
}
445
445
/* }}} */
446
446
447
- static int php_zip_get_num_files (struct zip * za ) /* {{{ */
447
+ static zend_long php_zip_get_num_files (struct zip * za ) /* {{{ */
448
448
{
449
- return zip_get_num_files (za );
449
+ zip_int64_t num = zip_get_num_entries (za , 0 );
450
+ return MIN (num , ZEND_LONG_MAX );
450
451
}
451
452
/* }}} */
452
453
@@ -784,7 +785,7 @@ static zend_object_handlers zip_object_handlers;
784
785
785
786
static HashTable zip_prop_handlers ;
786
787
787
- typedef int (* zip_read_int_t )(struct zip * za );
788
+ typedef zend_long (* zip_read_int_t )(struct zip * za );
788
789
typedef char * (* zip_read_const_char_t )(struct zip * za , int * len );
789
790
typedef char * (* zip_read_const_char_from_ze_t )(ze_zip_object * obj );
790
791
@@ -1177,7 +1178,7 @@ static PHP_NAMED_FUNCTION(zif_zip_open)
1177
1178
}
1178
1179
1179
1180
rsrc_int -> index_current = 0 ;
1180
- rsrc_int -> num_files = zip_get_num_files (rsrc_int -> za );
1181
+ rsrc_int -> num_files = zip_get_num_entries (rsrc_int -> za , 0 );
1181
1182
1182
1183
RETURN_RES (zend_register_resource (rsrc_int , le_zip_dir ));
1183
1184
}
@@ -1553,10 +1554,12 @@ static ZIPARCHIVE_METHOD(count)
1553
1554
{
1554
1555
struct zip * intern ;
1555
1556
zval * self = ZEND_THIS ;
1557
+ zip_int64_t num ;
1556
1558
1557
1559
ZIP_FROM_OBJECT (intern , self );
1558
1560
1559
- RETVAL_LONG (zip_get_num_files (intern ));
1561
+ num = zip_get_num_entries (intern , 0 );
1562
+ RETVAL_LONG (MIN (num , ZEND_LONG_MAX ));
1560
1563
}
1561
1564
/* }}} */
1562
1565
@@ -1840,7 +1843,7 @@ static ZIPARCHIVE_METHOD(addFromString)
1840
1843
}
1841
1844
}
1842
1845
1843
- if (zip_add (intern , name , zs ) == -1 ) {
1846
+ if (zip_file_add (intern , name , zs , 0 ) == -1 ) {
1844
1847
zip_source_free (zs );
1845
1848
RETURN_FALSE ;
1846
1849
} else {
@@ -1966,7 +1969,13 @@ static ZIPARCHIVE_METHOD(setArchiveComment)
1966
1969
if (zend_parse_parameters (ZEND_NUM_ARGS (), "s" , & comment , & comment_len ) == FAILURE ) {
1967
1970
return ;
1968
1971
}
1969
- if (zip_set_archive_comment (intern , (const char * )comment , (int )comment_len )) {
1972
+
1973
+ if (comment_len > 0xffff ) {
1974
+ php_error_docref (NULL , E_WARNING , "Comment must not exceed 65535 bytes" );
1975
+ RETURN_FALSE ;
1976
+ }
1977
+
1978
+ if (zip_set_archive_comment (intern , (const char * )comment , comment_len )) {
1970
1979
RETURN_FALSE ;
1971
1980
} else {
1972
1981
RETURN_TRUE ;
@@ -2019,6 +2028,11 @@ static ZIPARCHIVE_METHOD(setCommentName)
2019
2028
php_error_docref (NULL , E_NOTICE , "Empty string as entry name" );
2020
2029
}
2021
2030
2031
+ if (comment_len > 0xffff ) {
2032
+ php_error_docref (NULL , E_WARNING , "Comment must not exceed 65535 bytes" );
2033
+ RETURN_FALSE ;
2034
+ }
2035
+
2022
2036
idx = zip_name_locate (intern , name , 0 );
2023
2037
if (idx < 0 ) {
2024
2038
RETURN_FALSE ;
@@ -2045,6 +2059,11 @@ static ZIPARCHIVE_METHOD(setCommentIndex)
2045
2059
return ;
2046
2060
}
2047
2061
2062
+ if (comment_len > 0xffff ) {
2063
+ php_error_docref (NULL , E_WARNING , "Comment must not exceed 65535 bytes" );
2064
+ RETURN_FALSE ;
2065
+ }
2066
+
2048
2067
PHP_ZIP_STAT_INDEX (intern , index , 0 , sb );
2049
2068
PHP_ZIP_SET_FILE_COMMENT (intern , index , comment , comment_len );
2050
2069
}
@@ -2249,7 +2268,7 @@ static ZIPARCHIVE_METHOD(getCommentName)
2249
2268
size_t name_len ;
2250
2269
int idx ;
2251
2270
zend_long flags = 0 ;
2252
- int comment_len = 0 ;
2271
+ zip_uint32_t comment_len = 0 ;
2253
2272
const char * comment ;
2254
2273
char * name ;
2255
2274
@@ -2269,8 +2288,8 @@ static ZIPARCHIVE_METHOD(getCommentName)
2269
2288
RETURN_FALSE ;
2270
2289
}
2271
2290
2272
- comment = zip_get_file_comment (intern , idx , & comment_len , (int )flags );
2273
- RETURN_STRINGL ((char * )comment , ( zend_long ) comment_len );
2291
+ comment = zip_file_get_comment (intern , idx , & comment_len , (zip_flags_t )flags );
2292
+ RETURN_STRINGL ((char * )comment , comment_len );
2274
2293
}
2275
2294
/* }}} */
2276
2295
@@ -2282,7 +2301,7 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
2282
2301
zval * self = ZEND_THIS ;
2283
2302
zend_long index , flags = 0 ;
2284
2303
const char * comment ;
2285
- int comment_len = 0 ;
2304
+ zip_uint32_t comment_len = 0 ;
2286
2305
struct zip_stat sb ;
2287
2306
2288
2307
ZIP_FROM_OBJECT (intern , self );
@@ -2293,8 +2312,8 @@ static ZIPARCHIVE_METHOD(getCommentIndex)
2293
2312
}
2294
2313
2295
2314
PHP_ZIP_STAT_INDEX (intern , index , 0 , sb );
2296
- comment = zip_get_file_comment (intern , index , & comment_len , (int )flags );
2297
- RETURN_STRINGL ((char * )comment , ( zend_long ) comment_len );
2315
+ comment = zip_file_get_comment (intern , index , & comment_len , (zip_flags_t )flags );
2316
+ RETURN_STRINGL ((char * )comment , comment_len );
2298
2317
}
2299
2318
/* }}} */
2300
2319
@@ -2435,7 +2454,7 @@ static ZIPARCHIVE_METHOD(renameIndex)
2435
2454
php_error_docref (NULL , E_NOTICE , "Empty string as new entry name" );
2436
2455
RETURN_FALSE ;
2437
2456
}
2438
- if (zip_rename (intern , index , (const char * )new_name ) != 0 ) {
2457
+ if (zip_file_rename (intern , index , (const char * )new_name , 0 ) != 0 ) {
2439
2458
RETURN_FALSE ;
2440
2459
}
2441
2460
RETURN_TRUE ;
@@ -2465,7 +2484,7 @@ static ZIPARCHIVE_METHOD(renameName)
2465
2484
2466
2485
PHP_ZIP_STAT_PATH (intern , name , name_len , 0 , sb );
2467
2486
2468
- if (zip_rename (intern , sb .index , (const char * )new_name )) {
2487
+ if (zip_file_rename (intern , sb .index , (const char * )new_name , 0 )) {
2469
2488
RETURN_FALSE ;
2470
2489
}
2471
2490
RETURN_TRUE ;
@@ -2579,9 +2598,7 @@ static ZIPARCHIVE_METHOD(extractTo)
2579
2598
php_stream_statbuf ssb ;
2580
2599
char * pathto ;
2581
2600
size_t pathto_len ;
2582
- int ret , i ;
2583
-
2584
- int nelems ;
2601
+ int ret ;
2585
2602
2586
2603
if (zend_parse_parameters (ZEND_NUM_ARGS (), "p|z" , & pathto , & pathto_len , & zval_files ) == FAILURE ) {
2587
2604
return ;
@@ -2600,6 +2617,8 @@ static ZIPARCHIVE_METHOD(extractTo)
2600
2617
2601
2618
ZIP_FROM_OBJECT (intern , self );
2602
2619
if (zval_files && (Z_TYPE_P (zval_files ) != IS_NULL )) {
2620
+ uint32_t nelems , i ;
2621
+
2603
2622
switch (Z_TYPE_P (zval_files )) {
2604
2623
case IS_STRING :
2605
2624
if (!php_zip_extract_file (intern , pathto , Z_STRVAL_P (zval_files ), Z_STRLEN_P (zval_files ))) {
@@ -2632,7 +2651,7 @@ static ZIPARCHIVE_METHOD(extractTo)
2632
2651
}
2633
2652
} else {
2634
2653
/* Extract all files */
2635
- int filecount = zip_get_num_files (intern );
2654
+ zip_int64_t i , filecount = zip_get_num_entries (intern , 0 );
2636
2655
2637
2656
if (filecount == -1 ) {
2638
2657
php_error_docref (NULL , E_WARNING , "Illegal archive" );
0 commit comments