php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #60826
Patch iis-cgi-chunked-poc revision 2020-02-27 17:50 UTC by cmb@php.net
Patch IIS-FastCGI-transfer-encoding-chuncked revision 2012-04-11 13:52 UTC by andres at fenestrae dot com

Patch iis-cgi-chunked-poc for CGI/CLI related Bug #60826

Patch version 2020-02-27 17:50 UTC

Return to Bug #60826 | Download this patch
Patch Revisions:

Developer: cmb@php.net

 sapi/cgi/cgi_main.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index 29c61e9a18..9bc02c0f9b 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -480,7 +480,7 @@ static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes)
 	int tmp_read_bytes;
 	size_t remaining_bytes;
 
-	assert(SG(request_info).content_length >= SG(read_post_bytes));
+	assert(SG(request_info).content_length >= SG(read_post_bytes) || SG(request_info).content_length == -1);
 
 	remaining_bytes = (size_t)(SG(request_info).content_length - SG(read_post_bytes));
 
@@ -490,7 +490,17 @@ static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes)
 		size_t diff = count_bytes - read_bytes;
 		unsigned int to_read = (diff > UINT_MAX) ? UINT_MAX : (unsigned int)diff;
 
-		tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, to_read);
+		tmp_read_bytes = _read(STDIN_FILENO, buffer + read_bytes, to_read);
+		if (tmp_read_bytes < to_read && SG(request_info).content_length == -1) {
+			DWORD totalBytesAvail;
+			usleep(100);
+			PeekNamedPipe(_get_osfhandle(STDIN_FILENO), NULL, 0, NULL, &totalBytesAvail, NULL);
+			if (totalBytesAvail == 0) {
+				read_bytes += tmp_read_bytes;
+				SG(request_info).content_length = SG(read_post_bytes) + read_bytes;
+			}
+			break;
+		}
 #else
 		tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes);
 #endif
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC