cURL / Mailing Lists / curl-library / Single Mail

curl-library

Bug in curl 7.19 for CURLINFO_CONTENT_LENGTH_DOWNLOAD?

From: Gabriel Kuri <gkuri_at_ieee.org>
Date: Wed, 21 Oct 2009 15:18:14 -0700

I am using the Linux FUSE driver to access the Amazon S3 storage cloud,
and ran into a problem recently when upgrading to curl 7.19 that I
believe is a bug in curl. Basically, files whose size should be zero
were instead showing up with size MAXINT. I traced this down to a
change in lib/getinfo.c:

  case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
    *param_doublep = (data->progress.flags & PGRS_DL_SIZE_KNOWN)?
      (double)data->progress.size_dl:-1;
    break;

Previously, this code simply returned data->progress.size_dl. Now, if
the PGRS_DL_SIZE_KNOWN bit is not set, it returns -1 instead. As the
FUSE driver driver casts the returned value into an unsigned variable,
the result ends up becoming MAXINT.

The PGRS_DL_SIZE_KNOWN bit is set by the following code in lib/progress.c:

void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size)
{
  data->progress.size_dl = size;
  if(size > 0)
    data->progress.flags |= PGRS_DL_SIZE_KNOWN;
  else
    data->progress.flags &= ~PGRS_DL_SIZE_KNOWN;
}

However, I believe a Content-Length of 0 is valid, not unknown -- this
code would appear to be considering the size as unknown if the size is
not greater than zero. This appears to result in the inability to
distinguish the difference between an unknown size and a size that is
truly 0 (ironically, the description of the bug the change to
lib/getinfo.c was intended to resolve ;) )

Based on the following comment in lib/urldata.h:

struct SingleRequest {
  curl_off_t size; /* -1 if unknown at this point */

Should the check in Curl_pgrsSetDownloadSize be for >=0 rather than >0?
If not, what would be a better way to allow the API to distinguish
between content-length unknown and content-length of zero?

-----
Gabriel Kuri | Sr. Network Engineer
Instructional and Information Technology Division
California State Polytechnic University, Pomona
http://www.csupomona.edu/~iit | +1 909 979 6363

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-10-22