cURL / Mailing Lists / curl-library / Single Mail

curl-library

minor bug fix for chunked uploads

From: Steve Roskowski <rosko_at_thirdiris.com>
Date: Fri, 17 Oct 2008 19:12:34 -0700

a minor bug fix...in 7.19.0.

when doing a chunked upload with a read callback function, if the
callback function returns a CURL_READFUNC_PAUSE result,
libcurl puts a faulty byte stream on the wire, inserting extra bytes
of grabage which causes the server to abandon the connection and
libcurl to get out of sink, spitting the remains of the upload into
the ether.

The fix is in /lib/transfer.c - Curl_fillreadbuffer as below
<SNIP>
CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
{
  struct SessionHandle *data = conn->data;
  size_t buffersize = (size_t)bytes;
  int nread;
  if(data->req.upload_chunky) {
    /* if chunked Transfer-Encoding */
    buffersize -= (8 + 2 + 2); /* 32bit hex + CRLF + CRLF */
    data->req.upload_fromhere += 10; /* 32bit hex + CRLF */
  }
  /* this function returns a size_t, so we typecast to int to prevent warnings
     with picky compilers */
  nread = (int)conn->fread_func(data->req.upload_fromhere, 1,
                                buffersize, conn->fread_in);
  if(nread == CURL_READFUNC_ABORT) {
    failf(data, "operation aborted by callback");
    *nreadp = 0;
    return CURLE_ABORTED_BY_CALLBACK;
  }
  else if(nread == CURL_READFUNC_PAUSE) {
    struct SingleRequest *k = &data->req;
    /* CURL_READFUNC_PAUSE pauses read callbacks that feed socket writes */
    k->keepon |= KEEP_WRITE_PAUSE; /* mark socket send as paused */
    *nreadp = 0;
    data->req.upload_fromhere -= 10; /* ***BUG FIX backout
preallocation above *** */
    return CURLE_OK; /* nothing was read */
  }
<SNIP>

hope that helps somebody

steve

-- 
Steve Roskowski
Received on 2008-10-18