summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-03-02 19:12:49 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-03-02 19:12:49 +0100
commitb9c157726bf4229d694ec840daf4dc6ccb1c3898 (patch)
treef9160b338fc87e00d46e100fc798fa20a7efcc71
parenta6d86c9bba6c700c6541252a17a70f84ab1bc826 (diff)
parentfc8b3ab7cbb4f5e77584babeaf25b9bf16f524cd (diff)
downloadphp-git-b9c157726bf4229d694ec840daf4dc6ccb1c3898.tar.gz
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79013: Content-Length missing when posting a curlFile with curl
-rw-r--r--ext/curl/interface.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/curl/interface.c b/ext/curl/interface.c
index b86dd01178..22a4823a32 100644
--- a/ext/curl/interface.c
+++ b/ext/curl/interface.c
@@ -1983,6 +1983,10 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
char *type = NULL, *filename = NULL;
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
struct mime_data_cb_arg *cb_arg;
+ php_stream *stream;
+ php_stream_statbuf ssb;
+ size_t filesize = -1;
+ curl_seek_callback seekfunc = seek_cb;
#endif
prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0, &rv);
@@ -2008,9 +2012,17 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
zval_ptr_dtor(&ch->postfields);
ZVAL_COPY(&ch->postfields, zpostfields);
+ if ((stream = php_stream_open_wrapper(ZSTR_VAL(postval), "rb", STREAM_MUST_SEEK, NULL))) {
+ if (!stream->readfilters.head && !php_stream_stat(stream, &ssb)) {
+ filesize = ssb.sb.st_size;
+ }
+ } else {
+ seekfunc = NULL;
+ }
+
cb_arg = emalloc(sizeof *cb_arg);
cb_arg->filename = zend_string_copy(postval);
- cb_arg->stream = NULL;
+ cb_arg->stream = stream;
part = curl_mime_addpart(mime);
if (part == NULL) {
@@ -2018,7 +2030,7 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
return FAILURE;
}
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
- || (form_error = curl_mime_data_cb(part, -1, read_cb, seek_cb, free_cb, cb_arg)) != CURLE_OK
+ || (form_error = curl_mime_data_cb(part, filesize, read_cb, seekfunc, free_cb, cb_arg)) != CURLE_OK
|| (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
|| (form_error = curl_mime_type(part, type ? type : "application/octet-stream")) != CURLE_OK) {
error = form_error;