andrei                                   Thu, 18 Mar 2010 21:07:38 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=296358

Log:
Fix a few problems with large (2G-4G) file uploads. Added
--enable-large-uploads-fix switch because one change was in SAPI.h structure.

Changed paths:
    U   php/php-src/branches/PHP_5_2/configure.in
    U   php/php-src/branches/PHP_5_2/ext/standard/file.c
    U   php/php-src/branches/PHP_5_2/main/SAPI.c
    U   php/php-src/branches/PHP_5_2/main/SAPI.h
    U   php/php-src/branches/PHP_5_2/main/rfc1867.c
    U   php/php-src/branches/PHP_5_3/configure.in
    U   php/php-src/branches/PHP_5_3/ext/standard/file.c
    U   php/php-src/branches/PHP_5_3/main/SAPI.c
    U   php/php-src/branches/PHP_5_3/main/SAPI.h
    U   php/php-src/branches/PHP_5_3/main/rfc1867.c

Modified: php/php-src/branches/PHP_5_2/configure.in
===================================================================
--- php/php-src/branches/PHP_5_2/configure.in	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_2/configure.in	2010-03-18 21:07:38 UTC (rev 296358)
@@ -896,6 +896,12 @@
   AC_MSG_RESULT([using system default])
 fi

+PHP_ARG_ENABLE(large-uploads-fix, whether to enable large files (2G-4G) uploads fix,
+[  --enable-large-uploads-fix Enable large files (2G-4G) uploads fix], no, no)
+if test "$PHP_LARGE_UPLOADS_FIX" = "yes"; then
+	AC_DEFINE(HAVE_LARGE_UPLOADS_FIX, 1, [Whether to enable large files (2G-4G) uploads fix])
+fi
+
 divert(5)

 dnl ## In diversion 5 we check which extensions should be compiled.

Modified: php/php-src/branches/PHP_5_2/ext/standard/file.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/standard/file.c	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_2/ext/standard/file.c	2010-03-18 21:07:38 UTC (rev 296358)
@@ -579,7 +579,8 @@
 	char *filename;
 	int filename_len;
 	zval *data;
-	int numbytes = 0;
+	size_t numbytes = 0;
+	int result = SUCCESS;
 	long flags = 0;
 	zval *zcontext = NULL;
 	php_stream_context *context = NULL;
@@ -622,7 +623,7 @@
 		case IS_RESOURCE: {
 			size_t len;
 			if (php_stream_copy_to_stream_ex(srcstream, stream, PHP_STREAM_COPY_ALL, &len) != SUCCESS) {
-				numbytes = -1;
+				result = FAILURE;
 			} else {
 				numbytes = len;
 			}
@@ -640,7 +641,7 @@
 				numbytes = php_stream_write(stream, Z_STRVAL_P(data), Z_STRLEN_P(data));
 				if (numbytes != Z_STRLEN_P(data)) {
 					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));
-					numbytes = -1;
+					result = FAILURE;
 				}
 			}
 			break;
@@ -666,7 +667,7 @@
 							} else {
 								php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space",  bytes_written, Z_STRLEN_PP(tmp));
 							}
-							numbytes = -1;
+							result = FAILURE;
 							break;
 						}
 					}
@@ -683,19 +684,19 @@
 					numbytes = php_stream_write(stream, Z_STRVAL(out), Z_STRLEN(out));
 					if (numbytes != Z_STRLEN(out)) {
 						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN(out));
-						numbytes = -1;
+						result = FAILURE;
 					}
 					zval_dtor(&out);
 					break;
 				}
 			}
 		default:
-			numbytes = -1;
+			result = FAILURE;
 			break;
 	}
 	php_stream_close(stream);

-	if (numbytes < 0) {
+	if (result == FAILURE) {
 		RETURN_FALSE;
 	}


Modified: php/php-src/branches/PHP_5_2/main/SAPI.c
===================================================================
--- php/php-src/branches/PHP_5_2/main/SAPI.c	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_2/main/SAPI.c	2010-03-18 21:07:38 UTC (rev 296358)
@@ -191,8 +191,8 @@

 SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
 {
-	int read_bytes;
-	int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
+	size_t read_bytes;
+	size_t allocated_bytes=SAPI_POST_BLOCK_SIZE+1;

 	if (SG(request_info).content_length > SG(post_max_size)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes",

Modified: php/php-src/branches/PHP_5_2/main/SAPI.h
===================================================================
--- php/php-src/branches/PHP_5_2/main/SAPI.h	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_2/main/SAPI.h	2010-03-18 21:07:38 UTC (rev 296358)
@@ -118,7 +118,11 @@
 	void *server_context;
 	sapi_request_info request_info;
 	sapi_headers_struct sapi_headers;
+#ifdef HAVE_LARGE_UPLOADS_FIX
+	size_t read_post_bytes;
+#else
 	int read_post_bytes;
+#endif
 	unsigned char headers_sent;
 	struct stat global_stat;
 	char *default_mimetype;

Modified: php/php-src/branches/PHP_5_2/main/rfc1867.c
===================================================================
--- php/php-src/branches/PHP_5_2/main/rfc1867.c	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_2/main/rfc1867.c	2010-03-18 21:07:38 UTC (rev 296358)
@@ -765,8 +765,9 @@
 {
 	char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL;
 	char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL;
-	int boundary_len = 0, total_bytes = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
-	int max_file_size = 0, skip_upload = 0, anonindex = 0, is_anonymous;
+	int boundary_len = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
+	int skip_upload = 0, anonindex = 0, is_anonymous;
+	size_t total_bytes = 0, max_file_size = 0;
 	zval *http_post_files = NULL;
 	HashTable *uploaded_files = NULL;
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)

Modified: php/php-src/branches/PHP_5_3/configure.in
===================================================================
--- php/php-src/branches/PHP_5_3/configure.in	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_3/configure.in	2010-03-18 21:07:38 UTC (rev 296358)
@@ -916,6 +916,12 @@
   AC_MSG_RESULT([using system default])
 fi

+PHP_ARG_ENABLE(large-uploads-fix, whether to enable large files (2G-4G) uploads fix,
+[  --enable-large-uploads-fix Enable large files (2G-4G) uploads fix], no, no)
+if test "$PHP_LARGE_UPLOADS_FIX" = "yes"; then
+	AC_DEFINE(HAVE_LARGE_UPLOADS_FIX, 1, [Whether to enable large files (2G-4G) uploads fix])
+fi
+
 divert(5)

 dnl ## In diversion 5 we check which extensions should be compiled.

Modified: php/php-src/branches/PHP_5_3/ext/standard/file.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/file.c	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_3/ext/standard/file.c	2010-03-18 21:07:38 UTC (rev 296358)
@@ -584,7 +584,8 @@
 	char *filename;
 	int filename_len;
 	zval *data;
-	int numbytes = 0;
+	size_t numbytes = 0;
+	int result = SUCCESS;
 	long flags = 0;
 	zval *zcontext = NULL;
 	php_stream_context *context = NULL;
@@ -634,7 +635,7 @@
 		case IS_RESOURCE: {
 			size_t len;
 			if (php_stream_copy_to_stream_ex(srcstream, stream, PHP_STREAM_COPY_ALL, &len) != SUCCESS) {
-				numbytes = -1;
+				result = FAILURE;
 			} else {
 				numbytes = len;
 			}
@@ -652,7 +653,7 @@
 				numbytes = php_stream_write(stream, Z_STRVAL_P(data), Z_STRLEN_P(data));
 				if (numbytes != Z_STRLEN_P(data)) {
 					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));
-					numbytes = -1;
+					result = FAILURE;
 				}
 			}
 			break;
@@ -678,7 +679,7 @@
 							} else {
 								php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", bytes_written, Z_STRLEN_PP(tmp));
 							}
-							numbytes = -1;
+							result = FAILURE;
 							break;
 						}
 					}
@@ -695,19 +696,19 @@
 					numbytes = php_stream_write(stream, Z_STRVAL(out), Z_STRLEN(out));
 					if (numbytes != Z_STRLEN(out)) {
 						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN(out));
-						numbytes = -1;
+						result = FAILURE;
 					}
 					zval_dtor(&out);
 					break;
 				}
 			}
 		default:
-			numbytes = -1;
+			result = FAILURE;
 			break;
 	}
 	php_stream_close(stream);

-	if (numbytes < 0) {
+	if (result == FAILURE) {
 		RETURN_FALSE;
 	}


Modified: php/php-src/branches/PHP_5_3/main/SAPI.c
===================================================================
--- php/php-src/branches/PHP_5_3/main/SAPI.c	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_3/main/SAPI.c	2010-03-18 21:07:38 UTC (rev 296358)
@@ -191,8 +191,8 @@

 SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
 {
-	int read_bytes;
-	int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
+	size_t read_bytes;
+	size_t allocated_bytes=SAPI_POST_BLOCK_SIZE+1;

 	if (SG(request_info).content_length > SG(post_max_size)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes",

Modified: php/php-src/branches/PHP_5_3/main/SAPI.h
===================================================================
--- php/php-src/branches/PHP_5_3/main/SAPI.h	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_3/main/SAPI.h	2010-03-18 21:07:38 UTC (rev 296358)
@@ -120,7 +120,11 @@
 	void *server_context;
 	sapi_request_info request_info;
 	sapi_headers_struct sapi_headers;
+#ifdef HAVE_LARGE_UPLOADS_FIX
+	size_t read_post_bytes;
+#else
 	int read_post_bytes;
+#endif
 	unsigned char headers_sent;
 	struct stat global_stat;
 	char *default_mimetype;

Modified: php/php-src/branches/PHP_5_3/main/rfc1867.c
===================================================================
--- php/php-src/branches/PHP_5_3/main/rfc1867.c	2010-03-18 19:42:55 UTC (rev 296357)
+++ php/php-src/branches/PHP_5_3/main/rfc1867.c	2010-03-18 21:07:38 UTC (rev 296358)
@@ -764,8 +764,9 @@
 {
 	char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL;
 	char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL;
-	int boundary_len = 0, total_bytes = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
-	int max_file_size = 0, skip_upload = 0, anonindex = 0, is_anonymous;
+	int boundary_len = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
+	int skip_upload = 0, anonindex = 0, is_anonymous;
+	size_t total_bytes = 0, max_file_size = 0;
 	zval *http_post_files = NULL;
 	HashTable *uploaded_files = NULL;
 #if HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING)
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to