]> granicus.if.org Git - curl/commitdiff
file_range: avoid integer overflow when figuring out byte range
authorDaniel Stenberg <daniel@haxx.se>
Fri, 22 Sep 2017 12:24:39 +0000 (14:24 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 23 Sep 2017 16:21:15 +0000 (18:21 +0200)
When trying to bump the value with one and the value is already at max,
it causes an integer overflow.

Closes #1908
Detected by oss-fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3465

Assisted-by: Max Dymond
lib/file.c

index 82c576f38378bf94eee041989f7c97c1d0117283..7cfdab19f52180658fa66246d77937f3c71d40ab 100644 (file)
@@ -165,6 +165,9 @@ static CURLcode file_range(struct connectdata *conn)
     else {
       /* X-Y */
       totalsize = to-from;
+      if(totalsize == CURL_OFF_T_MAX)
+        /* this is too big to increase, so bail out */
+        return CURLE_RANGE_ERROR;
       data->req.maxdownload = totalsize + 1; /* include last byte */
       data->state.resume_from = from;
       DEBUGF(infof(data, "RANGE from %" CURL_FORMAT_CURL_OFF_T