@@ -2422,6 +2422,15 @@ PHP_METHOD(ZipArchive, setCompressionIndex)
24222422 RETURN_THROWS ();
24232423 }
24242424
2425+ if (index < 0 ) {
2426+ RETURN_FALSE ;
2427+ }
2428+
2429+ if (comp_flags < 0 || comp_flags > USHRT_MAX ) {
2430+ // comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2431+ RETURN_FALSE ;
2432+ }
2433+
24252434 ZIP_FROM_OBJECT (intern , this );
24262435
24272436 RETURN_BOOL (zip_set_file_compression (intern , (zip_uint64_t )index ,
@@ -2444,13 +2453,13 @@ PHP_METHOD(ZipArchive, setMtimeName)
24442453 RETURN_THROWS ();
24452454 }
24462455
2447- ZIP_FROM_OBJECT (intern , this );
2448-
24492456 if (name_len == 0 ) {
24502457 zend_argument_must_not_be_empty_error (1 );
24512458 RETURN_THROWS ();
24522459 }
24532460
2461+ ZIP_FROM_OBJECT (intern , this );
2462+
24542463 idx = zip_name_locate (intern , name , 0 );
24552464
24562465 if (idx < 0 ) {
@@ -2516,17 +2525,15 @@ PHP_METHOD(ZipArchive, deleteName)
25162525 RETURN_THROWS ();
25172526 }
25182527
2519- ZIP_FROM_OBJECT (intern , self );
2520-
25212528 if (name_len < 1 ) {
25222529 RETURN_FALSE ;
25232530 }
25242531
2532+ ZIP_FROM_OBJECT (intern , self );
2533+
25252534 PHP_ZIP_STAT_PATH (intern , name , name_len , 0 , sb );
2526- if (zip_delete (intern , sb .index )) {
2527- RETURN_FALSE ;
2528- }
2529- RETURN_TRUE ;
2535+
2536+ RETURN_BOOL (zip_delete (intern , sb .index ) == 0 );
25302537}
25312538/* }}} */
25322539
@@ -2547,13 +2554,13 @@ PHP_METHOD(ZipArchive, renameIndex)
25472554 RETURN_FALSE ;
25482555 }
25492556
2550- ZIP_FROM_OBJECT (intern , self );
2551-
25522557 if (new_name_len == 0 ) {
25532558 zend_argument_must_not_be_empty_error (2 );
25542559 RETURN_THROWS ();
25552560 }
25562561
2562+ ZIP_FROM_OBJECT (intern , self );
2563+
25572564 RETURN_BOOL (zip_file_rename (intern , index , (const char * )new_name , 0 ) == 0 );
25582565}
25592566/* }}} */
@@ -2595,12 +2602,12 @@ PHP_METHOD(ZipArchive, unchangeIndex)
25952602 RETURN_THROWS ();
25962603 }
25972604
2598- ZIP_FROM_OBJECT (intern , self );
2599-
26002605 if (index < 0 ) {
26012606 RETURN_FALSE ;
26022607 }
26032608
2609+ ZIP_FROM_OBJECT (intern , self );
2610+
26042611 RETURN_BOOL (zip_unchange (intern , index ) == 0 );
26052612}
26062613/* }}} */
@@ -2618,12 +2625,12 @@ PHP_METHOD(ZipArchive, unchangeName)
26182625 RETURN_THROWS ();
26192626 }
26202627
2621- ZIP_FROM_OBJECT (intern , self );
2622-
26232628 if (name_len < 1 ) {
26242629 RETURN_FALSE ;
26252630 }
26262631
2632+ ZIP_FROM_OBJECT (intern , self );
2633+
26272634 PHP_ZIP_STAT_PATH (intern , name , name_len , 0 , sb );
26282635
26292636 RETURN_BOOL (zip_unchange (intern , sb .index ) == 0 );
@@ -2687,8 +2694,6 @@ PHP_METHOD(ZipArchive, extractTo)
26872694 Z_PARAM_ARRAY_HT_OR_STR_OR_NULL (files_ht , files_str )
26882695 ZEND_PARSE_PARAMETERS_END ();
26892696
2690- ZIP_FROM_OBJECT (intern , self );
2691-
26922697 if (pathto_len < 1 ) {
26932698 RETURN_FALSE ;
26942699 }
@@ -2701,6 +2706,7 @@ PHP_METHOD(ZipArchive, extractTo)
27012706 }
27022707
27032708 uint32_t nelems , i ;
2709+ ZIP_FROM_OBJECT (intern , self );
27042710
27052711 if (files_str ) {
27062712 if (!php_zip_extract_file (intern , pathto , ZSTR_VAL (files_str ), ZSTR_LEN (files_str ), -1 )) {
@@ -2797,7 +2803,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
27972803 RETURN_FALSE ;
27982804 }
27992805
2800- buffer = zend_string_safe_alloc (1 , len , 0 , 0 );
2806+ buffer = zend_string_safe_alloc (1 , len , 0 , false );
28012807 n = zip_fread (zf , ZSTR_VAL (buffer ), ZSTR_LEN (buffer ));
28022808 if (n < 1 ) {
28032809 zend_string_efree (buffer );
@@ -3006,6 +3012,9 @@ PHP_METHOD(ZipArchive, isCompressionMethodSupported)
30063012 if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
30073013 return ;
30083014 }
3015+ if (method < 0 ) {
3016+ RETURN_FALSE ;
3017+ }
30093018 RETVAL_BOOL (zip_compression_method_supported ((zip_int32_t )method , enc ));
30103019}
30113020/* }}} */
@@ -3019,6 +3028,9 @@ PHP_METHOD(ZipArchive, isEncryptionMethodSupported)
30193028 if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
30203029 return ;
30213030 }
3031+ if (method < 0 ) {
3032+ RETURN_FALSE ;
3033+ }
30223034 RETVAL_BOOL (zip_encryption_method_supported ((zip_uint16_t )method , enc ));
30233035}
30243036/* }}} */
0 commit comments