Skip to content

Commit da04b2e

Browse files
committed
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
1 parent a441d92 commit da04b2e

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

main/SAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef struct {
8282
char *post_data, *raw_post_data;
8383
char *cookie_data;
8484
long content_length;
85-
uint post_data_length, raw_post_data_length;
85+
off_t post_data_length, raw_post_data_length;
8686

8787
char *path_translated;
8888
char *request_uri;
@@ -119,7 +119,7 @@ typedef struct _sapi_globals_struct {
119119
void *server_context;
120120
sapi_request_info request_info;
121121
sapi_headers_struct sapi_headers;
122-
int read_post_bytes;
122+
off_t read_post_bytes;
123123
unsigned char headers_sent;
124124
struct stat global_stat;
125125
char *default_mimetype;

main/rfc1867.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,9 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
676676
{
677677
char *boundary, *s = NULL, *boundary_end = NULL, *start_arr = NULL, *array_index = NULL;
678678
char *temp_filename = NULL, *lbuf = NULL, *abuf = NULL;
679-
int boundary_len = 0, total_bytes = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
680-
int max_file_size = 0, skip_upload = 0, anonindex = 0, is_anonymous;
679+
int boundary_len = 0, cancel_upload = 0, is_arr_upload = 0, array_len = 0;
680+
off_t total_bytes = 0, max_file_size = 0;
681+
int skip_upload = 0, anonindex = 0, is_anonymous;
681682
zval *http_post_files = NULL;
682683
HashTable *uploaded_files = NULL;
683684
multipart_buffer *mbuff;

sapi/cgi/cgi_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
508508
uint read_bytes = 0;
509509
int tmp_read_bytes;
510510

511-
count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes));
511+
count_bytes = MIN(count_bytes, SG(request_info).content_length - SG(read_post_bytes));
512512
while (read_bytes < count_bytes) {
513513
tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes);
514514
if (tmp_read_bytes <= 0) {

0 commit comments

Comments
 (0)