Skip to content

Commit a931a6d

Browse files
ndosschejmarble
authored andcommitted
zip: Don't truncate return value of zip_fread() with user sizes
The return type has been zip_int64_t since 2009, so we shouldn't truncate to an int because the user may have requested a size that won't fit in an int. Closes phpGH-20509.
1 parent 6e774b1 commit a931a6d

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ PHP NEWS
5757

5858
- Zip:
5959
. Fix crash in property existence test. (ndossche)
60+
. Don't truncate return value of zip_fread() with user sizes. (ndossche)
6061

6162
- Zlib:
6263
. Fix assertion failures resulting in crashes with stream filter

ext/zip/php_zip.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,6 @@ PHP_FUNCTION(zip_entry_read)
13031303
zend_long len = 0;
13041304
zip_read_rsrc * zr_rsrc;
13051305
zend_string *buffer;
1306-
int n = 0;
13071306

13081307
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zip_entry, &len) == FAILURE) {
13091308
RETURN_THROWS();
@@ -1318,8 +1317,8 @@ PHP_FUNCTION(zip_entry_read)
13181317
}
13191318

13201319
if (zr_rsrc->zf) {
1321-
buffer = zend_string_safe_alloc(1, len, 0, false);
1322-
n = zip_fread(zr_rsrc->zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
1320+
buffer = zend_string_safe_alloc(1, len, 0, 0);
1321+
zip_int64_t n = zip_fread(zr_rsrc->zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
13231322
if (n > 0) {
13241323
ZSTR_VAL(buffer)[n] = '\0';
13251324
ZSTR_LEN(buffer) = n;
@@ -2781,8 +2780,6 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
27812780
zend_string *filename;
27822781
zend_string *buffer;
27832782

2784-
int n = 0;
2785-
27862783
if (type == 1) {
27872784
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) {
27882785
RETURN_THROWS();
@@ -2818,8 +2815,8 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
28182815
RETURN_FALSE;
28192816
}
28202817

2821-
buffer = zend_string_safe_alloc(1, len, 0, false);
2822-
n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
2818+
buffer = zend_string_safe_alloc(1, len, 0, 0);
2819+
zip_int64_t n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
28232820
if (n < 1) {
28242821
zend_string_efree(buffer);
28252822
RETURN_EMPTY_STRING();

0 commit comments

Comments
 (0)