diff options
author | Anatol Belski <ab@php.net> | 2013-08-14 18:59:46 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2013-08-14 18:59:46 +0200 |
commit | 9d4e5b0dbab21ecba3536136ce8241862fa813b0 (patch) | |
tree | ab6a5f3d9b59d75f426d7625ff1d2010c56a7f42 | |
parent | 4da62730927ea469e74577a269072ed1069ab05f (diff) | |
download | php-git-9d4e5b0dbab21ecba3536136ce8241862fa813b0.tar.gz |
Fix to file uploads >2G with size overflow
Represent the file size as string when the total size would overflow
LONG_MAX. Otherwise while file itself were uploaded, the size would
be shown wrong. This mostly applies to systems with 32 bit long.
-rw-r--r-- | main/rfc1867.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/main/rfc1867.c b/main/rfc1867.c index 3c160702ae..498b59725c 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -1215,17 +1215,32 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ { zval file_size, error_type; + int size_overflow = 0; + char file_size_buf[65]; - error_type.value.lval = cancel_upload; - error_type.type = IS_LONG; + ZVAL_LONG(&error_type, cancel_upload); /* Add $foo[error] */ if (cancel_upload) { - file_size.value.lval = 0; - file_size.type = IS_LONG; + ZVAL_LONG(&file_size, 0); } else { - file_size.value.lval = total_bytes; - file_size.type = IS_LONG; + if (total_bytes > LONG_MAX) { +#ifdef PHP_WIN32 + if (_i64toa_s(total_bytes, file_size_buf, 65, 10)) { + file_size_buf[0] = '0'; + file_size_buf[1] = '\0'; + } +#else + { + int __len = snprintf(file_size_buf, 65, "%lld", total_bytes); + file_size_buf[__len] = '\0'; + } +#endif + size_overflow = 1; + + } else { + ZVAL_LONG(&file_size, total_bytes); + } } if (is_arr_upload) { @@ -1242,7 +1257,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ snprintf(lbuf, llen, "%s_size", param); } if (!is_anonymous) { - safe_php_register_variable_ex(lbuf, &file_size, NULL, 0 TSRMLS_CC); + if (size_overflow) { + ZVAL_STRING(&file_size, file_size_buf, 1); + } + safe_php_register_variable_ex(lbuf, &file_size, NULL, size_overflow TSRMLS_CC); } /* Add $foo[size] */ @@ -1251,7 +1269,10 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } else { snprintf(lbuf, llen, "%s[size]", param); } - register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, 0 TSRMLS_CC); + if (size_overflow) { + ZVAL_STRING(&file_size, file_size_buf, 1); + } + register_http_post_files_variable_ex(lbuf, &file_size, http_post_files, size_overflow TSRMLS_CC); } efree(param); } |