transfer: speed limiting fix for 32bit systems

When checking if a speed limit on receives applies, compare the receive
sizes using the large int type to prevent an overflow on systems where
size_t is 32bit.

Fixes #14272
Reported-by: Mamoru Tasaka
Closes #14277
This commit is contained in:
Stefan Eissing 2024-07-26 10:38:45 +02:00 committed by Daniel Stenberg
parent 11e248b782
commit fc273027f1
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -281,13 +281,13 @@ static CURLcode readwrite_data(struct Curl_easy *data,
buf = xfer_buf;
bytestoread = xfer_blen;
if(bytestoread && data->set.max_recv_speed) {
if(bytestoread && data->set.max_recv_speed > 0) {
/* In case of speed limit on receiving: if this loop already got
* data, break out. If not, limit the amount of bytes to receive.
* The overall, timed, speed limiting is done in multi.c */
if(total_received)
break;
if((size_t)data->set.max_recv_speed < bytestoread)
if(data->set.max_recv_speed < (curl_off_t)bytestoread)
bytestoread = (size_t)data->set.max_recv_speed;
}