From: Stefan Eissing Date: Tue, 5 Mar 2024 10:08:55 +0000 (+0100) Subject: transfer.c: break receive loop in speed limited transfers X-Git-Tag: curl-8_7_0~77 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db5c9f4f9e0779b49624752b135281a0717b277b;p=thirdparty%2Fcurl.git transfer.c: break receive loop in speed limited transfers - the change breaks looping in transfer.c receive for transfers that are speed limited on having gotten *some* bytes. - the overall speed limit timing is done in multi.c Reported-by: Dmitry Karpov Bug: https://curl.se/mail/lib-2024-03/0001.html Closes #13050 --- diff --git a/lib/transfer.c b/lib/transfer.c index cd3bd37682..669beebd3a 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -242,13 +242,14 @@ static CURLcode readwrite_data(struct Curl_easy *data, buf = xfer_buf; bytestoread = xfer_blen; - /* Observe any imposed speed limit */ if(bytestoread && data->set.max_recv_speed) { - curl_off_t net_limit = data->set.max_recv_speed - total_received; - if(net_limit <= 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)net_limit < bytestoread) - bytestoread = (size_t)net_limit; + if((size_t)data->set.max_recv_speed < bytestoread) + bytestoread = (size_t)data->set.max_recv_speed; } nread = Curl_xfer_recv_resp(data, buf, bytestoread,