@@ -335,7 +335,7 @@ typedef struct {
335
335
#endif
336
336
} zip_options ;
337
337
338
- static int php_zip_parse_options (HashTable * options , zip_options * opts )
338
+ static bool php_zip_parse_options (HashTable * options , zip_options * opts )
339
339
/* {{{ */
340
340
{
341
341
zval * option ;
@@ -349,25 +349,46 @@ static int php_zip_parse_options(HashTable *options, zip_options *opts)
349
349
#endif
350
350
351
351
if ((option = zend_hash_str_find (options , "remove_all_path" , sizeof ("remove_all_path" ) - 1 )) != NULL ) {
352
- opts -> remove_all_path = zval_get_long (option );
352
+ if (Z_TYPE_P (option ) != IS_FALSE && Z_TYPE_P (option ) != IS_TRUE ) {
353
+ zend_type_error ("Option \"remove_all_path\" must be of type bool, %s given" ,
354
+ zend_zval_type_name (option ));
355
+ return false;
356
+ }
357
+ opts -> remove_all_path = Z_LVAL_P (option );
353
358
}
354
359
355
360
if ((option = zend_hash_str_find (options , "comp_method" , sizeof ("comp_method" ) - 1 )) != NULL ) {
356
- opts -> comp_method = zval_get_long (option );
361
+ if (Z_TYPE_P (option ) != IS_LONG ) {
362
+ zend_type_error ("Option \"comp_method\" must be of type int, %s given" ,
363
+ zend_zval_type_name (option ));
364
+ return false;
365
+ }
366
+ opts -> comp_method = Z_LVAL_P (option );
357
367
358
368
if ((option = zend_hash_str_find (options , "comp_flags" , sizeof ("comp_flags" ) - 1 )) != NULL ) {
359
- opts -> comp_flags = zval_get_long (option );
369
+ if (Z_TYPE_P (option ) != IS_LONG ) {
370
+ zend_type_error ("Option \"comp_flags\" must be of type int, %s given" ,
371
+ zend_zval_type_name (option ));
372
+ return false;
373
+ }
374
+ opts -> comp_flags = Z_LVAL_P (option );
360
375
}
361
376
}
362
377
363
378
#ifdef HAVE_ENCRYPTION
364
379
if ((option = zend_hash_str_find (options , "enc_method" , sizeof ("enc_method" ) - 1 )) != NULL ) {
365
- opts -> enc_method = zval_get_long (option );
380
+ if (Z_TYPE_P (option ) != IS_LONG ) {
381
+ zend_type_error ("Option \"enc_method\" must be of type int, %s given" ,
382
+ zend_zval_type_name (option ));
383
+ return false;
384
+ }
385
+ opts -> enc_method = Z_LVAL_P (option );
366
386
367
387
if ((option = zend_hash_str_find (options , "enc_password" , sizeof ("enc_password" ) - 1 )) != NULL ) {
368
388
if (Z_TYPE_P (option ) != IS_STRING ) {
369
- php_error_docref (NULL , E_WARNING , "enc_password option expected to be a string" );
370
- return -1 ;
389
+ zend_type_error ("Option \"enc_password\" must be of type string, %s given" ,
390
+ zend_zval_type_name (option ));
391
+ return false;
371
392
}
372
393
opts -> enc_password = Z_STRVAL_P (option );
373
394
}
@@ -376,53 +397,54 @@ static int php_zip_parse_options(HashTable *options, zip_options *opts)
376
397
377
398
if ((option = zend_hash_str_find (options , "remove_path" , sizeof ("remove_path" ) - 1 )) != NULL ) {
378
399
if (Z_TYPE_P (option ) != IS_STRING ) {
379
- php_error_docref (NULL , E_WARNING , "remove_path option expected to be a string" );
380
- return -1 ;
400
+ zend_type_error ("Option \"remove_path\" must be of type string, %s given" ,
401
+ zend_zval_type_name (option ));
402
+ return false;
381
403
}
382
404
383
- if (Z_STRLEN_P (option ) < 1 ) {
384
- php_error_docref ( NULL , E_NOTICE , "Empty string given as remove_path option " );
385
- return -1 ;
405
+ if (Z_STRLEN_P (option ) == 0 ) {
406
+ zend_type_error ( "Option \"remove_path\" cannot be empty " );
407
+ return false ;
386
408
}
387
409
388
410
if (Z_STRLEN_P (option ) >= MAXPATHLEN ) {
389
- php_error_docref (NULL , E_WARNING , "remove_path string is too long (max: %d, %zd given)" ,
390
- MAXPATHLEN - 1 , Z_STRLEN_P (option ));
391
- return -1 ;
411
+ zend_type_error ("Option \"remove_path\" must be less than %d bytes" , MAXPATHLEN - 1 );
412
+ return false;
392
413
}
393
414
opts -> remove_path_len = Z_STRLEN_P (option );
394
415
opts -> remove_path = Z_STRVAL_P (option );
395
416
}
396
417
397
418
if ((option = zend_hash_str_find (options , "add_path" , sizeof ("add_path" ) - 1 )) != NULL ) {
398
419
if (Z_TYPE_P (option ) != IS_STRING ) {
399
- php_error_docref (NULL , E_WARNING , "add_path option expected to be a string" );
400
- return -1 ;
420
+ zend_type_error ("Option \"add_path\" must be of type string, %s given" ,
421
+ zend_zval_type_name (option ));
422
+ return false;
401
423
}
402
424
403
- if (Z_STRLEN_P (option ) < 1 ) {
404
- php_error_docref ( NULL , E_NOTICE , "Empty string given as the add_path option " );
405
- return -1 ;
425
+ if (Z_STRLEN_P (option ) == 0 ) {
426
+ zend_type_error ( "Option \"add_path\" cannot be empty " );
427
+ return false ;
406
428
}
407
429
408
430
if (Z_STRLEN_P (option ) >= MAXPATHLEN ) {
409
- php_error_docref (NULL , E_WARNING , "add_path string too long (max: %d, %zd given)" ,
410
- MAXPATHLEN - 1 , Z_STRLEN_P (option ));
411
- return -1 ;
431
+ zend_type_error ("Option \"add_path\" must be less than %d bytes" , MAXPATHLEN - 1 );
432
+ return false;
412
433
}
413
434
opts -> add_path_len = Z_STRLEN_P (option );
414
435
opts -> add_path = Z_STRVAL_P (option );
415
436
}
416
437
417
438
if ((option = zend_hash_str_find (options , "flags" , sizeof ("flags" ) - 1 )) != NULL ) {
418
439
if (Z_TYPE_P (option ) != IS_LONG ) {
419
- php_error_docref (NULL , E_WARNING , "flags option expected to be a integer" );
420
- return -1 ;
440
+ zend_type_error ("Option \"flags\" must be of type int, %s given" ,
441
+ zend_zval_type_name (option ));
442
+ return false;
421
443
}
422
444
opts -> flags = Z_LVAL_P (option );
423
445
}
424
446
425
- return 1 ;
447
+ return true ;
426
448
}
427
449
/* }}} */
428
450
@@ -1683,8 +1705,8 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
1683
1705
zend_argument_value_error (1 , "cannot be empty" );
1684
1706
RETURN_THROWS ();
1685
1707
}
1686
- if (options && zend_hash_num_elements (options ) > 0 && (php_zip_parse_options (options , & opts ) < 0 )) {
1687
- RETURN_FALSE ;
1708
+ if (options && zend_hash_num_elements (options ) > 0 && (php_zip_parse_options (options , & opts ) == false )) {
1709
+ RETURN_THROWS () ;
1688
1710
}
1689
1711
1690
1712
if (type == 1 ) {
0 commit comments