@@ -2417,6 +2417,15 @@ PHP_METHOD(ZipArchive, setCompressionIndex)
24172417 RETURN_THROWS ();
24182418 }
24192419
2420+ if (index < 0 ) {
2421+ RETURN_FALSE ;
2422+ }
2423+
2424+ if (comp_flags < 0 || comp_flags > USHRT_MAX ) {
2425+ // comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2426+ RETURN_FALSE ;
2427+ }
2428+
24202429 ZIP_FROM_OBJECT (intern , this );
24212430
24222431 RETURN_BOOL (zip_set_file_compression (intern , (zip_uint64_t )index ,
@@ -2440,13 +2449,13 @@ PHP_METHOD(ZipArchive, setMtimeName)
24402449 RETURN_THROWS ();
24412450 }
24422451
2443- ZIP_FROM_OBJECT (intern , this );
2444-
24452452 if (name_len == 0 ) {
24462453 zend_argument_must_not_be_empty_error (1 );
24472454 RETURN_THROWS ();
24482455 }
24492456
2457+ ZIP_FROM_OBJECT (intern , this );
2458+
24502459 idx = zip_name_locate (intern , name , 0 );
24512460
24522461 if (idx < 0 ) {
@@ -2513,17 +2522,15 @@ PHP_METHOD(ZipArchive, deleteName)
25132522 RETURN_THROWS ();
25142523 }
25152524
2516- ZIP_FROM_OBJECT (intern , self );
2517-
25182525 if (name_len < 1 ) {
25192526 RETURN_FALSE ;
25202527 }
25212528
2529+ ZIP_FROM_OBJECT (intern , self );
2530+
25222531 PHP_ZIP_STAT_PATH (intern , name , name_len , 0 , sb );
2523- if (zip_delete (intern , sb .index )) {
2524- RETURN_FALSE ;
2525- }
2526- RETURN_TRUE ;
2532+
2533+ RETURN_BOOL (zip_delete (intern , sb .index ) == 0 );
25272534}
25282535/* }}} */
25292536
@@ -2544,13 +2551,13 @@ PHP_METHOD(ZipArchive, renameIndex)
25442551 RETURN_FALSE ;
25452552 }
25462553
2547- ZIP_FROM_OBJECT (intern , self );
2548-
25492554 if (new_name_len == 0 ) {
25502555 zend_argument_must_not_be_empty_error (2 );
25512556 RETURN_THROWS ();
25522557 }
25532558
2559+ ZIP_FROM_OBJECT (intern , self );
2560+
25542561 RETURN_BOOL (zip_file_rename (intern , index , (const char * )new_name , 0 ) == 0 );
25552562}
25562563/* }}} */
@@ -2592,12 +2599,12 @@ PHP_METHOD(ZipArchive, unchangeIndex)
25922599 RETURN_THROWS ();
25932600 }
25942601
2595- ZIP_FROM_OBJECT (intern , self );
2596-
25972602 if (index < 0 ) {
25982603 RETURN_FALSE ;
25992604 }
26002605
2606+ ZIP_FROM_OBJECT (intern , self );
2607+
26012608 RETURN_BOOL (zip_unchange (intern , index ) == 0 );
26022609}
26032610/* }}} */
@@ -2615,12 +2622,12 @@ PHP_METHOD(ZipArchive, unchangeName)
26152622 RETURN_THROWS ();
26162623 }
26172624
2618- ZIP_FROM_OBJECT (intern , self );
2619-
26202625 if (name_len < 1 ) {
26212626 RETURN_FALSE ;
26222627 }
26232628
2629+ ZIP_FROM_OBJECT (intern , self );
2630+
26242631 PHP_ZIP_STAT_PATH (intern , name , name_len , 0 , sb );
26252632
26262633 RETURN_BOOL (zip_unchange (intern , sb .index ) == 0 );
@@ -2684,8 +2691,6 @@ PHP_METHOD(ZipArchive, extractTo)
26842691 Z_PARAM_ARRAY_HT_OR_STR_OR_NULL (files_ht , files_str )
26852692 ZEND_PARSE_PARAMETERS_END ();
26862693
2687- ZIP_FROM_OBJECT (intern , self );
2688-
26892694 if (pathto_len < 1 ) {
26902695 RETURN_FALSE ;
26912696 }
@@ -2698,6 +2703,7 @@ PHP_METHOD(ZipArchive, extractTo)
26982703 }
26992704
27002705 uint32_t nelems , i ;
2706+ ZIP_FROM_OBJECT (intern , self );
27012707
27022708 if (files_str ) {
27032709 if (!php_zip_extract_file (intern , pathto , ZSTR_VAL (files_str ), ZSTR_LEN (files_str ), -1 )) {
@@ -2794,7 +2800,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
27942800 RETURN_FALSE ;
27952801 }
27962802
2797- buffer = zend_string_safe_alloc (1 , len , 0 , 0 );
2803+ buffer = zend_string_safe_alloc (1 , len , 0 , false );
27982804 n = zip_fread (zf , ZSTR_VAL (buffer ), ZSTR_LEN (buffer ));
27992805 if (n < 1 ) {
28002806 zend_string_efree (buffer );
@@ -3003,6 +3009,9 @@ PHP_METHOD(ZipArchive, isCompressionMethodSupported)
30033009 if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
30043010 return ;
30053011 }
3012+ if (method < 0 ) {
3013+ RETURN_FALSE ;
3014+ }
30063015 RETVAL_BOOL (zip_compression_method_supported ((zip_int32_t )method , enc ));
30073016}
30083017/* }}} */
@@ -3016,6 +3025,9 @@ PHP_METHOD(ZipArchive, isEncryptionMethodSupported)
30163025 if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
30173026 return ;
30183027 }
3028+ if (method < 0 ) {
3029+ RETURN_FALSE ;
3030+ }
30193031 RETVAL_BOOL (zip_encryption_method_supported ((zip_uint16_t )method , enc ));
30203032}
30213033/* }}} */
0 commit comments