curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Seek problem with curl_formadd with CURLFORM_STREAM

From: Jeff Mears via curl-library <curl-library_at_lists.haxx.se>
Date: Mon, 29 Jan 2024 19:33:59 +0000

I have code that's attempting to use CURLFORM_STREAM with curl_formadd, and it is getting a CURLE_SEND_FAIL_REWIND error from the library.

Looking at the libcurl code, it looks like it might be a bug, but it's hard for me to tell for sure. A full example of how the library is being used would take a while to construct.

curl_formadd(&download->m_postMulti, &download->m_lastMulti,
                CURLFORM_COPYNAME, uploadName,
                CURLFORM_FILENAME, uploadFilename,
                CURLFORM_CONTENTTYPE, uploadContentType,
                CURLFORM_STREAM, download,
                CURLFORM_CONTENTSLENGTH, static_cast<long>(download->m_uploadSize),
                CURLFORM_END);

I expected my read callbacks to get called, but instead, the transfer fails with CURLE_SEND_FAIL_REWIND. I have a seek callback set in addition to a read callback.

Tracing through the code, I find that it's because curl_mimepart::seekfunc is set to null. In formdata.c there is this:

        else if(post->flags & HTTPPOST_CALLBACK) {
          /* the contents should be read with the callback and the size is set
             with the contentslength */
          if(!clen)
            clen = -1;
          result = curl_mime_data_cb(part, clen,
                                     fread_func, NULL, NULL, post->userp);
        }

There is no seek function being given to curl_mime_data_cb in Curl_getformdata, resulting in mime_part_rewind failing, finally causing a CURLE_SEND_FAIL_REWIND.

Is this a bug in libcurl? My code is fairly old at this point, and wasn't written to use curl_mime_*. Using curl_mime_data_cb solves the problem, because I can provide the seek callback.

Thanks~



-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2024-01-29