@@ -527,7 +527,7 @@ PHP_FUNCTION(file_get_contents)
527
527
char * contents ;
528
528
zend_bool use_include_path = 0 ;
529
529
php_stream * stream ;
530
- int len ;
530
+ long len ;
531
531
long offset = -1 ;
532
532
long maxlen = PHP_STREAM_COPY_ALL ;
533
533
zval * zcontext = NULL ;
@@ -559,6 +559,10 @@ PHP_FUNCTION(file_get_contents)
559
559
}
560
560
561
561
if ((len = php_stream_copy_to_mem (stream , & contents , maxlen , 0 )) > 0 ) {
562
+ if (len > INT_MAX ) {
563
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "content truncated from %ld to %d bytes" , len , INT_MAX );
564
+ len = INT_MAX ;
565
+ }
562
566
RETVAL_STRINGL (contents , len , 0 );
563
567
} else if (len == 0 ) {
564
568
RETVAL_EMPTY_STRING ();
@@ -578,7 +582,7 @@ PHP_FUNCTION(file_put_contents)
578
582
char * filename ;
579
583
int filename_len ;
580
584
zval * data ;
581
- int numbytes = 0 ;
585
+ long numbytes = 0 ;
582
586
long flags = 0 ;
583
587
zval * zcontext = NULL ;
584
588
php_stream_context * context = NULL ;
@@ -630,6 +634,10 @@ PHP_FUNCTION(file_put_contents)
630
634
if (php_stream_copy_to_stream_ex (srcstream , stream , PHP_STREAM_COPY_ALL , & len ) != SUCCESS ) {
631
635
numbytes = -1 ;
632
636
} else {
637
+ if (len > LONG_MAX ) {
638
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "content truncated from %lu to %ld bytes" , (unsigned long ) len , LONG_MAX );
639
+ len = LONG_MAX ;
640
+ }
633
641
numbytes = len ;
634
642
}
635
643
break ;
@@ -645,7 +653,7 @@ PHP_FUNCTION(file_put_contents)
645
653
if (Z_STRLEN_P (data )) {
646
654
numbytes = php_stream_write (stream , Z_STRVAL_P (data ), Z_STRLEN_P (data ));
647
655
if (numbytes != Z_STRLEN_P (data )) {
648
- 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 ));
656
+ 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 ));
649
657
numbytes = -1 ;
650
658
}
651
659
}
@@ -688,7 +696,7 @@ PHP_FUNCTION(file_put_contents)
688
696
if (zend_std_cast_object_tostring (data , & out , IS_STRING TSRMLS_CC ) == SUCCESS ) {
689
697
numbytes = php_stream_write (stream , Z_STRVAL (out ), Z_STRLEN (out ));
690
698
if (numbytes != Z_STRLEN (out )) {
691
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Only %d of %d bytes written, possibly out of free disk space" , numbytes , Z_STRLEN (out ));
699
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Only %ld of %d bytes written, possibly out of free disk space" , numbytes , Z_STRLEN (out ));
692
700
numbytes = -1 ;
693
701
}
694
702
zval_dtor (& out );
0 commit comments