Skip to content

Commit b9c1577

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79013: Content-Length missing when posting a curlFile with curl
2 parents a6d86c9 + fc8b3ab commit b9c1577

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ext/curl/interface.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,10 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
19831983
char *type = NULL, *filename = NULL;
19841984
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
19851985
struct mime_data_cb_arg *cb_arg;
1986+
php_stream *stream;
1987+
php_stream_statbuf ssb;
1988+
size_t filesize = -1;
1989+
curl_seek_callback seekfunc = seek_cb;
19861990
#endif
19871991

19881992
prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0, &rv);
@@ -2008,17 +2012,25 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
20082012
zval_ptr_dtor(&ch->postfields);
20092013
ZVAL_COPY(&ch->postfields, zpostfields);
20102014

2015+
if ((stream = php_stream_open_wrapper(ZSTR_VAL(postval), "rb", STREAM_MUST_SEEK, NULL))) {
2016+
if (!stream->readfilters.head && !php_stream_stat(stream, &ssb)) {
2017+
filesize = ssb.sb.st_size;
2018+
}
2019+
} else {
2020+
seekfunc = NULL;
2021+
}
2022+
20112023
cb_arg = emalloc(sizeof *cb_arg);
20122024
cb_arg->filename = zend_string_copy(postval);
2013-
cb_arg->stream = NULL;
2025+
cb_arg->stream = stream;
20142026

20152027
part = curl_mime_addpart(mime);
20162028
if (part == NULL) {
20172029
zend_string_release_ex(string_key, 0);
20182030
return FAILURE;
20192031
}
20202032
if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
2021-
|| (form_error = curl_mime_data_cb(part, -1, read_cb, seek_cb, free_cb, cb_arg)) != CURLE_OK
2033+
|| (form_error = curl_mime_data_cb(part, filesize, read_cb, seekfunc, free_cb, cb_arg)) != CURLE_OK
20222034
|| (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
20232035
|| (form_error = curl_mime_type(part, type ? type : "application/octet-stream")) != CURLE_OK) {
20242036
error = form_error;

0 commit comments

Comments
 (0)