Skip to content

Commit 2f05830

Browse files
committed
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 GH-20509.
1 parent 6054a90 commit 2f05830

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

NEWS

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

5353
- Zip:
5454
. Fix crash in property existence test. (ndossche)
55+
. Don't truncate return value of zip_fread() with user sizes. (ndossche)
5556

5657
- Zlib:
5758
. Fix assertion failures resulting in crashes with stream filter

ext/zip/php_zip.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,6 @@ PHP_FUNCTION(zip_entry_read)
13321332
zend_long len = 0;
13331333
zip_read_rsrc * zr_rsrc;
13341334
zend_string *buffer;
1335-
int n = 0;
13361335

13371336
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &zip_entry, &len) == FAILURE) {
13381337
RETURN_THROWS();
@@ -1348,7 +1347,7 @@ PHP_FUNCTION(zip_entry_read)
13481347

13491348
if (zr_rsrc->zf) {
13501349
buffer = zend_string_safe_alloc(1, len, 0, 0);
1351-
n = zip_fread(zr_rsrc->zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
1350+
zip_int64_t n = zip_fread(zr_rsrc->zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
13521351
if (n > 0) {
13531352
ZSTR_VAL(buffer)[n] = '\0';
13541353
ZSTR_LEN(buffer) = n;
@@ -2910,8 +2909,6 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
29102909
zend_string *filename;
29112910
zend_string *buffer;
29122911

2913-
int n = 0;
2914-
29152912
if (type == 1) {
29162913
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) {
29172914
RETURN_THROWS();
@@ -2948,7 +2945,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
29482945
}
29492946

29502947
buffer = zend_string_safe_alloc(1, len, 0, 0);
2951-
n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
2948+
zip_int64_t n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
29522949
if (n < 1) {
29532950
zend_string_efree(buffer);
29542951
RETURN_EMPTY_STRING();

0 commit comments

Comments
 (0)