@@ -792,8 +792,19 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
792
792
} else if (!strncasecmp (http_header_line , "Content-Type:" , sizeof ("Content-Type:" )- 1 )) {
793
793
php_stream_notify_info (context , PHP_STREAM_NOTIFY_MIME_TYPE_IS , http_header_value , 0 );
794
794
} else if (!strncasecmp (http_header_line , "Content-Length:" , sizeof ("Content-Length:" )- 1 )) {
795
- file_size = atoi (http_header_value );
796
- php_stream_notify_file_size (context , file_size , http_header_line , 0 );
795
+ /* https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length */
796
+ const char * ptr = http_header_value ;
797
+ /* must contain only digits, no + or - symbols */
798
+ if (* ptr >= '0' && * ptr <= '9' ) {
799
+ char * endptr = NULL ;
800
+ size_t parsed = ZEND_STRTOUL (ptr , & endptr , 10 );
801
+ /* check whether there was no garbage in the header value and the conversion was successful */
802
+ if (endptr && !* endptr ) {
803
+ /* truncate for 32-bit such that no negative file sizes occur */
804
+ file_size = MIN (parsed , ZEND_LONG_MAX );
805
+ php_stream_notify_file_size (context , file_size , http_header_line , 0 );
806
+ }
807
+ }
797
808
} else if (
798
809
!strncasecmp (http_header_line , "Transfer-Encoding:" , sizeof ("Transfer-Encoding:" )- 1 )
799
810
&& !strncasecmp (http_header_value , "Chunked" , sizeof ("Chunked" )- 1 )
0 commit comments