Skip to content

Commit 1614151

Browse files
committed
Better size check in bzdecompress
1 parent 64e2832 commit 1614151

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ext/bz2/bz2.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,7 @@ PHP_FUNCTION(bzdecompress)
493493
size_t source_len;
494494
int error;
495495
bool small = 0;
496-
#ifdef PHP_WIN32
497-
unsigned __int64 size = 0;
498-
#else
499496
unsigned long long size = 0;
500-
#endif
501497
bz_stream bzs;
502498

503499
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &source, &source_len, &small)) {
@@ -524,7 +520,7 @@ PHP_FUNCTION(bzdecompress)
524520
/* compression is better then 2:1, need to allocate more memory */
525521
bzs.avail_out = source_len;
526522
size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32;
527-
#ifndef ZEND_ENABLE_ZVAL_LONG64
523+
#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T
528524
if (size > SIZE_MAX) {
529525
/* no reason to continue if we're going to drop it anyway */
530526
break;
@@ -536,9 +532,9 @@ PHP_FUNCTION(bzdecompress)
536532

537533
if (error == BZ_STREAM_END || error == BZ_OK) {
538534
size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32;
539-
#ifndef ZEND_ENABLE_ZVAL_LONG64
535+
#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T
540536
if (UNEXPECTED(size > SIZE_MAX)) {
541-
php_error_docref(NULL, E_WARNING, "Decompressed size too big, max is %zd", SIZE_MAX);
537+
php_error_docref(NULL, E_WARNING, "Decompressed size too big, max is %zu", SIZE_MAX);
542538
zend_string_efree(dest);
543539
RETVAL_LONG(BZ_MEM_ERROR);
544540
} else

0 commit comments

Comments
 (0)