Skip to content

Commit 08e7d9f

Browse files
committed
apply comp_flags type check for setCompressionName()/setCompressionIndex().
and throw exception for these
1 parent f4e4712 commit 08e7d9f

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
@@ -2391,13 +2391,19 @@ PHP_METHOD(ZipArchive, setCompressionName)
23912391
RETURN_THROWS();
23922392
}
23932393

2394-
ZIP_FROM_OBJECT(intern, this);
2394+
2395+
if (comp_flags < 0 || comp_flags > USHRT_MAX) {
2396+
// comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2397+
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
2398+
RETURN_THROWS();
2399+
}
23952400

23962401
if (name_len == 0) {
23972402
zend_argument_must_not_be_empty_error(1);
23982403
RETURN_THROWS();
23992404
}
24002405

2406+
ZIP_FROM_OBJECT(intern, this);
24012407
idx = zip_name_locate(intern, name, 0);
24022408

24032409
if (idx < 0) {
@@ -2428,7 +2434,8 @@ PHP_METHOD(ZipArchive, setCompressionIndex)
24282434

24292435
if (comp_flags < 0 || comp_flags > USHRT_MAX) {
24302436
// comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
2431-
RETURN_FALSE;
2437+
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
2438+
RETURN_THROWS();
24322439
}
24332440

24342441
ZIP_FROM_OBJECT(intern, this);

0 commit comments

Comments
 (0)