Skip to content

Commit 6df5f35

Browse files
tool_cb_prg: Fix integer overflow in progress bar
Commit 61faa0b fixed the progress bar width calculation to avoid integer overflow, but failed to account for the fact that initial_size is initialized to -1 when the file size is retrieved from the remote on an upload, causing another signed integer overflow. Fix by separately checking for this case before the width calculation. Closes curl#3984 Reported-by: Brian Carpenter (Geeknik Labs) Reviewed-by: Daniel Stenberg <daniel@haxx.se>
1 parent deb9462 commit 6df5f35

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/tool_cb_prg.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,19 @@ int tool_progress_cb(void *clientp,
125125
curl_off_t total;
126126
curl_off_t point;
127127

128-
/* expected transfer size */
129-
if((CURL_OFF_T_MAX - bar->initial_size) < (dltotal + ultotal))
128+
/* Calculate expected transfer size. initial_size can be less than zero
129+
when indicating that we are expecting to get the filesize from the
130+
remote */
131+
if(bar->initial_size < 0 ||
132+
((CURL_OFF_T_MAX - bar->initial_size) < (dltotal + ultotal)))
130133
total = CURL_OFF_T_MAX;
131134
else
132135
total = dltotal + ultotal + bar->initial_size;
133136

134-
/* we've come this far */
135-
if((CURL_OFF_T_MAX - bar->initial_size) < (dlnow + ulnow))
137+
/* Calculate the current progress. initial_size can be less than zero when
138+
indicating that we are expecting to get the filesize from the remote */
139+
if(bar->initial_size < 0 ||
140+
((CURL_OFF_T_MAX - bar->initial_size) < (dlnow + ulnow)))
136141
point = CURL_OFF_T_MAX;
137142
else
138143
point = dlnow + ulnow + bar->initial_size;

0 commit comments

Comments
 (0)