@@ -518,7 +518,7 @@ PHP_FUNCTION(file_get_contents)
518
518
char * contents ;
519
519
zend_bool use_include_path = 0 ;
520
520
php_stream * stream ;
521
- int len ;
521
+ long len ;
522
522
long offset = -1 ;
523
523
long maxlen = PHP_STREAM_COPY_ALL ;
524
524
zval * zcontext = NULL ;
@@ -550,6 +550,10 @@ PHP_FUNCTION(file_get_contents)
550
550
}
551
551
552
552
if ((len = php_stream_copy_to_mem (stream , & contents , maxlen , 0 )) > 0 ) {
553
+ if (len > INT_MAX ) {
554
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "content truncated from %ld to %d bytes" , len , INT_MAX );
555
+ len = INT_MAX ;
556
+ }
553
557
RETVAL_STRINGL (contents , len , 0 );
554
558
} else if (len == 0 ) {
555
559
RETVAL_EMPTY_STRING ();
@@ -569,7 +573,7 @@ PHP_FUNCTION(file_put_contents)
569
573
char * filename ;
570
574
int filename_len ;
571
575
zval * data ;
572
- int numbytes = 0 ;
576
+ long numbytes = 0 ;
573
577
long flags = 0 ;
574
578
zval * zcontext = NULL ;
575
579
php_stream_context * context = NULL ;
@@ -621,6 +625,10 @@ PHP_FUNCTION(file_put_contents)
621
625
if (php_stream_copy_to_stream_ex (srcstream , stream , PHP_STREAM_COPY_ALL , & len ) != SUCCESS ) {
622
626
numbytes = -1 ;
623
627
} else {
628
+ if (len > LONG_MAX ) {
629
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "content truncated from %lu to %ld bytes" , (unsigned long ) len , LONG_MAX );
630
+ len = LONG_MAX ;
631
+ }
624
632
numbytes = len ;
625
633
}
626
634
break ;
@@ -636,7 +644,7 @@ PHP_FUNCTION(file_put_contents)
636
644
if (Z_STRLEN_P (data )) {
637
645
numbytes = php_stream_write (stream , Z_STRVAL_P (data ), Z_STRLEN_P (data ));
638
646
if (numbytes != Z_STRLEN_P (data )) {
639
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Only %d of %d bytes written, possibly out of free disk space" , numbytes , Z_STRLEN_P (data ));
647
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Only %ld of %d bytes written, possibly out of free disk space" , numbytes , Z_STRLEN_P (data ));
640
648
numbytes = -1 ;
641
649
}
642
650
}
@@ -679,7 +687,7 @@ PHP_FUNCTION(file_put_contents)
679
687
if (zend_std_cast_object_tostring (data , & out , IS_STRING TSRMLS_CC ) == SUCCESS ) {
680
688
numbytes = php_stream_write (stream , Z_STRVAL (out ), Z_STRLEN (out ));
681
689
if (numbytes != Z_STRLEN (out )) {
682
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Only %d of %d bytes written, possibly out of free disk space" , numbytes , Z_STRLEN (out ));
690
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Only %ld of %d bytes written, possibly out of free disk space" , numbytes , Z_STRLEN (out ));
683
691
numbytes = -1 ;
684
692
}
685
693
zval_dtor (& out );
0 commit comments