From da04b2e28c6ccc73bfab542ed4dd5eada343e592 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Fri, 28 Jun 2013 08:32:10 +0200 Subject: [PATCH 1/5] Patch for https://bugs.php.net/bug.php?id=44522 to allow uploading files above 2G. This is essentially the same as the patch "uploads_larger_than_2g_HEAD_v2 (last revision 2012-03-26 03:59 UTC) by jason at infininull dot com)" but using off_t instead of signed long (originally: uint) I tested this on 64bit linux and succeeded uploading a file of 4.8 G. The File did not get corrupted or truncated in any way. I did not yet test this under windows or 32 bit linux Note that there are still limitations: * Did not test for files > 8 G * php does not yet reject absurdly high values * Still limited by underlying file system specific limits and free space * in upload * tmp dir and destination dir --- main/SAPI.h | 4 ++-- main/rfc1867.c | 5 +++-- sapi/cgi/cgi_main.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main/SAPI.h b/main/SAPI.h index 92b7329dbc16c..c3cacb515c78f 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -82,7 +82,7 @@ typedef struct { char *post_data, *raw_post_data; char *cookie_data; long content_length; - uint post_data_length, raw_post_data_length; + off_t post_data_length, raw_post_data_length; char *path_translated; char *request_uri; @@ -119,7 +119,7 @@ typedef struct _sapi_globals_struct { void *server_context; sapi_request_info request_info; sapi_headers_struct sapi_headers; - int read_post_bytes; + off_t read_post_bytes; unsigned char headers_sent; struct stat global_stat; char *default_mimetype; diff --git a/main/rfc1867.c b/main/rfc1867.c index ed7ce9c0c172b..78a7ad27946b0 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -676,8 +676,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ { 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; + off_t total_bytes = 0, max_file_size = 0; + int skip_upload = 0, anonindex = 0, is_anonymous; zval *http_post_files = NULL; HashTable *uploaded_files = NULL; multipart_buffer *mbuff; diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 9e6b74ac6164e..ec7b963339263 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -508,7 +508,7 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) uint read_bytes = 0; int tmp_read_bytes; - count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes)); + count_bytes = MIN(count_bytes, SG(request_info).content_length - SG(read_post_bytes)); while (read_bytes < count_bytes) { tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes); if (tmp_read_bytes <= 0) { From f978f11e2e599258cdbdc699cfccd5d961eb8c36 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Fri, 28 Jun 2013 08:38:34 +0200 Subject: [PATCH 2/5] ws --- main/rfc1867.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/rfc1867.c b/main/rfc1867.c index 78a7ad27946b0..452b6a332fd2c 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -677,7 +677,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ 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, cancel_upload = 0, is_arr_upload = 0, array_len = 0; - off_t total_bytes = 0, max_file_size = 0; + off_t total_bytes = 0, max_file_size = 0; int skip_upload = 0, anonindex = 0, is_anonymous; zval *http_post_files = NULL; HashTable *uploaded_files = NULL; From a2394df90e86a24a61f1267b5767017e2e769b2a Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Mon, 22 Jul 2013 18:03:11 +0200 Subject: [PATCH 3/5] Use int64_t and atoll() after discussion with johannes --- main/SAPI.h | 4 ++-- main/rfc1867.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/main/SAPI.h b/main/SAPI.h index c3cacb515c78f..6d5434d141b54 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -82,7 +82,7 @@ typedef struct { char *post_data, *raw_post_data; char *cookie_data; long content_length; - off_t post_data_length, raw_post_data_length; + int64_t post_data_length, raw_post_data_length; char *path_translated; char *request_uri; @@ -119,7 +119,7 @@ typedef struct _sapi_globals_struct { void *server_context; sapi_request_info request_info; sapi_headers_struct sapi_headers; - off_t read_post_bytes; + int64_t read_post_bytes; unsigned char headers_sent; struct stat global_stat; char *default_mimetype; diff --git a/main/rfc1867.c b/main/rfc1867.c index 452b6a332fd2c..d3adf4711407f 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -677,7 +677,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ 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, cancel_upload = 0, is_arr_upload = 0, array_len = 0; - off_t total_bytes = 0, max_file_size = 0; + int64_t total_bytes = 0, max_file_size = 0; int skip_upload = 0, anonindex = 0, is_anonymous; zval *http_post_files = NULL; HashTable *uploaded_files = NULL; @@ -899,7 +899,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } if (!strcasecmp(param, "MAX_FILE_SIZE")) { - max_file_size = atol(value); + max_file_size = atoll(value); } efree(param); From b07e55fdeba5d3e415671c0981e3041841b2485e Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Mon, 22 Jul 2013 21:26:38 +0200 Subject: [PATCH 4/5] make this work in vc11 too --- main/SAPI.h | 1 + main/rfc1867.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/main/SAPI.h b/main/SAPI.h index 6d5434d141b54..6fc60c886513e 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -27,6 +27,7 @@ #include "zend_operators.h" #ifdef PHP_WIN32 #include "win95nt.h" +#include "win32/php_stdint.h" #endif #include diff --git a/main/rfc1867.c b/main/rfc1867.c index d3adf4711407f..8460929108e10 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -34,6 +34,10 @@ #include "rfc1867.h" #include "ext/standard/php_string.h" +#if defined(_MSC_VER) +# define atoll(s) _atoi64(s) +#endif + #define DEBUG_FILE_UPLOAD ZEND_DEBUG static int dummy_encoding_translation(TSRMLS_D) From d80a91018dc0d7b771cf8517f788a408f3a4f473 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 23 Jul 2013 07:39:36 +0200 Subject: [PATCH 5/5] more precise condition --- main/rfc1867.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/rfc1867.c b/main/rfc1867.c index 8460929108e10..3c160702aef9c 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -34,7 +34,7 @@ #include "rfc1867.h" #include "ext/standard/php_string.h" -#if defined(_MSC_VER) +#if defined(PHP_WIN32) && !defined(HAVE_ATOLL) # define atoll(s) _atoi64(s) #endif