Skip to content

Commit 7cc4125

Browse files
committed
apply comp_flags type check for setCompressionName()/setCompressionIndex().
and throw exception for these
1 parent ab61a5c commit 7cc4125

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ext/zip/php_zip.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,13 +2386,19 @@ PHP_METHOD(ZipArchive, setCompressionName)
23862386
RETURN_THROWS();
23872387
}
23882388

2389-
ZIP_FROM_OBJECT(intern, this);
2389+
2390+
if (comp_flags < 0 || comp_flags > USHRT_MAX) {
2391+
// comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2392+
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
2393+
RETURN_THROWS();
2394+
}
23902395

23912396
if (name_len == 0) {
23922397
zend_argument_must_not_be_empty_error(1);
23932398
RETURN_THROWS();
23942399
}
23952400

2401+
ZIP_FROM_OBJECT(intern, this);
23962402
idx = zip_name_locate(intern, name, 0);
23972403

23982404
if (idx < 0) {
@@ -2423,7 +2429,8 @@ PHP_METHOD(ZipArchive, setCompressionIndex)
24232429

24242430
if (comp_flags < 0 || comp_flags > USHRT_MAX) {
24252431
// comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2426-
RETURN_FALSE;
2432+
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
2433+
RETURN_THROWS();
24272434
}
24282435

24292436
ZIP_FROM_OBJECT(intern, this);

0 commit comments

Comments
 (0)