Menu

#871 CURLINFO_CONTENT_LENGTH_DOWNLOAD returning -1 for size = 0

closed-fixed
libcurl (356)
5
2014-08-16
2009-10-23
Gabe
No

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?

Discussion

  • Daniel Stenberg

    Daniel Stenberg - 2009-10-31

    Thanks for the report, this problem is now fixed in CVS!

     
  • Daniel Stenberg

    Daniel Stenberg - 2009-10-31
    • milestone: --> wrong_behaviour
    • status: open --> closed-fixed