@@ -378,7 +378,11 @@ static zend_result php_zip_parse_options(HashTable *options, zip_options *opts)
378378 php_error_docref (NULL , E_WARNING , "Option \"comp_method\" must be of type int, %s given" ,
379379 zend_zval_value_name (option ));
380380 }
381- opts -> comp_method = zval_get_long (option );
381+ zend_long comp_method = zval_get_long (option );
382+ if (comp_method < 0 || comp_method > INT_MAX ) {
383+ php_error_docref (NULL , E_WARNING , "Option \"comp_method\" must be between 0 and %d" , INT_MAX );
384+ }
385+ opts -> comp_method = (zip_int32_t )comp_method ;
382386
383387 if ((option = zend_hash_str_find (options , "comp_flags" , sizeof ("comp_flags" ) - 1 )) != NULL ) {
384388 if (Z_TYPE_P (option ) != IS_LONG ) {
@@ -2388,15 +2392,19 @@ PHP_METHOD(ZipArchive, setCompressionName)
23882392 RETURN_THROWS ();
23892393 }
23902394
2395+ if (name_len == 0 ) {
2396+ zend_argument_must_not_be_empty_error (1 );
2397+ RETURN_THROWS ();
2398+ }
23912399
2392- if (comp_flags < 0 || comp_flags > USHRT_MAX ) {
2393- // comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2394- zend_argument_value_error (3 , "must be between 0 and %u" , USHRT_MAX );
2400+ if (comp_method < -1 || comp_method > INT_MAX ) {
2401+ zend_argument_value_error (2 , "must be between 0 and %d" , INT_MAX );
23952402 RETURN_THROWS ();
23962403 }
23972404
2398- if (name_len == 0 ) {
2399- zend_argument_must_not_be_empty_error (1 );
2405+ if (comp_flags < 0 || comp_flags > USHRT_MAX ) {
2406+ // comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2407+ zend_argument_value_error (3 , "must be between 0 and %u" , USHRT_MAX );
24002408 RETURN_THROWS ();
24012409 }
24022410
@@ -2429,6 +2437,11 @@ PHP_METHOD(ZipArchive, setCompressionIndex)
24292437 RETURN_FALSE ;
24302438 }
24312439
2440+ if (comp_method < -1 || comp_method > INT_MAX ) {
2441+ zend_argument_value_error (2 , "must be between -1 and %d" , INT_MAX );
2442+ RETURN_THROWS ();
2443+ }
2444+
24322445 if (comp_flags < 0 || comp_flags > USHRT_MAX ) {
24332446 // comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
24342447 zend_argument_value_error (3 , "must be between 0 and %u" , USHRT_MAX );
@@ -3016,8 +3029,9 @@ PHP_METHOD(ZipArchive, isCompressionMethodSupported)
30163029 if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
30173030 return ;
30183031 }
3019- if (method < 0 ) {
3020- RETURN_FALSE ;
3032+ if (method < -1 || method > INT_MAX ) {
3033+ zend_argument_value_error (1 , "must be between -1 and %d" , INT_MAX );
3034+ RETURN_THROWS ();
30213035 }
30223036 RETVAL_BOOL (zip_compression_method_supported ((zip_int32_t )method , enc ));
30233037}
@@ -3032,8 +3046,9 @@ PHP_METHOD(ZipArchive, isEncryptionMethodSupported)
30323046 if (zend_parse_parameters (ZEND_NUM_ARGS (), "l|b" , & method , & enc ) == FAILURE ) {
30333047 return ;
30343048 }
3035- if (method < 0 ) {
3036- RETURN_FALSE ;
3049+ if (method < 0 || method > USHRT_MAX ) {
3050+ zend_argument_value_error (1 , "must be between 0 and %u" , USHRT_MAX );
3051+ RETURN_THROWS ();
30373052 }
30383053 RETVAL_BOOL (zip_encryption_method_supported ((zip_uint16_t )method , enc ));
30393054}
0 commit comments