]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_progress: fix percent output of large parallel transfers
authorDaniel Stenberg <daniel@haxx.se>
Mon, 10 Feb 2025 09:15:44 +0000 (10:15 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 10 Feb 2025 10:12:44 +0000 (11:12 +0100)
When the total transfered amount (upload or download) for parallel
transfers was larger than 2^63/100 bytes (81 petabytes) the progress
percent counter would show wrong.

Closes #16284

src/tool_progress.c

index 3fac70a70e13903d54b6f9c6c22cab93609dfd64..c4df2111ae7a7084df6b2b51eb6a977816679095 100644 (file)
@@ -216,13 +216,16 @@ bool progress_meter(struct GlobalConfig *global,
         all_running++;
     }
     if(dlknown && all_dltotal)
-      /* TODO: handle integer overflow */
       msnprintf(dlpercen, sizeof(dlpercen), "%3" CURL_FORMAT_CURL_OFF_T,
-                all_dlnow * 100 / all_dltotal);
+                all_dlnow < (CURL_OFF_T_MAX/100) ?
+                (all_dlnow * 100 / all_dltotal) :
+                (all_dlnow / (all_dltotal/100)));
+
     if(ulknown && all_ultotal)
-      /* TODO: handle integer overflow */
       msnprintf(ulpercen, sizeof(ulpercen), "%3" CURL_FORMAT_CURL_OFF_T,
-                all_ulnow * 100 / all_ultotal);
+                all_ulnow < (CURL_OFF_T_MAX/100) ?
+                (all_ulnow * 100 / all_ultotal) :
+                (all_ulnow / (all_ultotal/100)));
 
     /* get the transfer speed, the higher of the two */