@@ -511,11 +511,7 @@ PHP_FUNCTION(bzdecompress)
511511 size_t source_len ;
512512 int error ;
513513 bool small = 0 ;
514- #ifdef PHP_WIN32
515- unsigned __int64 size = 0 ;
516- #else
517- unsigned long long size = 0 ;
518- #endif
514+ uint64_t size = 0 ;
519515 bz_stream bzs ;
520516
521517 if (FAILURE == zend_parse_parameters (ZEND_NUM_ARGS (), "s|b" , & source , & source_len , & small )) {
@@ -541,27 +537,22 @@ PHP_FUNCTION(bzdecompress)
541537 while ((error = BZ2_bzDecompress (& bzs )) == BZ_OK && bzs .avail_in > 0 ) {
542538 /* compression is better then 2:1, need to allocate more memory */
543539 bzs .avail_out = source_len ;
544- size = (bzs .total_out_hi32 * (unsigned int ) -1 ) + bzs .total_out_lo32 ;
545- #ifndef ZEND_ENABLE_ZVAL_LONG64
540+ size = (((uint64_t ) bzs .total_out_hi32 ) << 32U ) + bzs .total_out_lo32 ;
546541 if (size > SIZE_MAX ) {
547542 /* no reason to continue if we're going to drop it anyway */
548543 break ;
549544 }
550- #endif
551545 dest = zend_string_safe_realloc (dest , 1 , bzs .avail_out + 1 , (size_t ) size , 0 );
552546 bzs .next_out = ZSTR_VAL (dest ) + size ;
553547 }
554548
555549 if (error == BZ_STREAM_END || error == BZ_OK ) {
556- size = (bzs .total_out_hi32 * (unsigned int ) -1 ) + bzs .total_out_lo32 ;
557- #ifndef ZEND_ENABLE_ZVAL_LONG64
550+ size = (((uint64_t ) bzs .total_out_hi32 ) << 32U ) + bzs .total_out_lo32 ;
558551 if (UNEXPECTED (size > SIZE_MAX )) {
559552 php_error_docref (NULL , E_WARNING , "Decompressed size too big, max is %zd" , SIZE_MAX );
560553 zend_string_efree (dest );
561554 RETVAL_LONG (BZ_MEM_ERROR );
562- } else
563- #endif
564- {
555+ } else {
565556 dest = zend_string_safe_realloc (dest , 1 , (size_t )size , 1 , 0 );
566557 ZSTR_LEN (dest ) = (size_t )size ;
567558 ZSTR_VAL (dest )[(size_t )size ] = '\0' ;
0 commit comments