mirror of
https://github.com/curl/curl.git
synced 2026-08-05 21:16:13 +03:00
progress: count amount of data "delivered" to application
... and apply the CURLOPT_MAXFILESIZE limit (if set) on that as well. This effectively protects the user against "zip bombs". Test case 1618 verifies using a 14 byte brotli payload that otherwise explodes to 102400 zero bytes.
This commit is contained in:
parent
7fe5b933d8
commit
f6fce4f5ab
6 changed files with 90 additions and 6 deletions
11
lib/cw-out.c
11
lib/cw-out.c
|
|
@ -31,7 +31,7 @@
|
|||
#include "transfer.h"
|
||||
#include "cw-out.h"
|
||||
#include "cw-pause.h"
|
||||
|
||||
#include "progress.h"
|
||||
|
||||
/**
|
||||
* OVERALL DESIGN of this client writer
|
||||
|
|
@ -229,7 +229,7 @@ static CURLcode cw_out_ptr_flush(struct cw_out_ctx *ctx,
|
|||
void *wcb_data;
|
||||
size_t max_write, min_write;
|
||||
size_t wlen, nwritten;
|
||||
CURLcode result;
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
/* If we errored once, we do not invoke the client callback again */
|
||||
if(ctx->errored)
|
||||
|
|
@ -253,8 +253,11 @@ static CURLcode cw_out_ptr_flush(struct cw_out_ctx *ctx,
|
|||
if(!flush_all && blen < min_write)
|
||||
break;
|
||||
wlen = max_write ? CURLMIN(blen, max_write) : blen;
|
||||
result = cw_out_cb_write(ctx, data, wcb, wcb_data, otype,
|
||||
buf, wlen, &nwritten);
|
||||
if(otype == CW_OUT_BODY)
|
||||
result = Curl_pgrs_deliver_inc(data, wlen);
|
||||
if(!result)
|
||||
result = cw_out_cb_write(ctx, data, wcb, wcb_data, otype,
|
||||
buf, wlen, &nwritten);
|
||||
if(result)
|
||||
return result;
|
||||
*pconsumed += nwritten;
|
||||
|
|
|
|||
|
|
@ -211,6 +211,7 @@ void Curl_pgrsReset(struct Curl_easy *data)
|
|||
Curl_pgrsSetUploadSize(data, -1);
|
||||
Curl_pgrsSetDownloadSize(data, -1);
|
||||
data->progress.speeder_c = 0; /* reset speed records */
|
||||
data->progress.deliver = 0;
|
||||
pgrs_speedinit(data);
|
||||
}
|
||||
|
||||
|
|
@ -339,6 +340,17 @@ void Curl_pgrsStartNow(struct Curl_easy *data)
|
|||
p->ul_size_known = FALSE;
|
||||
}
|
||||
|
||||
/* this counts how much data is delivered to the application, which
|
||||
in compressed cases may differ from downloaded amount */
|
||||
CURLcode Curl_pgrs_deliver_inc(struct Curl_easy *data, size_t delta)
|
||||
{
|
||||
if(data->set.max_filesize &&
|
||||
(data->progress.deliver + (curl_off_t)delta > data->set.max_filesize))
|
||||
return CURLE_FILESIZE_EXCEEDED;
|
||||
data->progress.deliver += delta;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_pgrs_download_inc(struct Curl_easy *data, size_t delta)
|
||||
{
|
||||
if(delta) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ int Curl_pgrsDone(struct Curl_easy *data);
|
|||
void Curl_pgrsStartNow(struct Curl_easy *data);
|
||||
void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size);
|
||||
void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size);
|
||||
|
||||
CURLcode Curl_pgrs_deliver_inc(struct Curl_easy *data, size_t delta);
|
||||
void Curl_pgrs_download_inc(struct Curl_easy *data, size_t delta);
|
||||
void Curl_pgrs_upload_inc(struct Curl_easy *data, size_t delta);
|
||||
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size);
|
||||
|
|
|
|||
|
|
@ -796,6 +796,7 @@ struct Progress {
|
|||
force redraw at next call */
|
||||
struct pgrs_dir ul;
|
||||
struct pgrs_dir dl;
|
||||
curl_off_t deliver; /* amount of data delivered to application */
|
||||
|
||||
curl_off_t current_speed; /* uses the currently fastest transfer */
|
||||
curl_off_t earlydata_sent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue