diff options
author | Mikalai Ananenka <git@3dyd.com> | 2017-12-26 00:17:08 +0300 |
---|---|---|
committer | Patrick Monnerat <patrick@monnerat.net> | 2017-12-27 13:00:54 +0100 |
commit | 58d7cd28a0d8306c91be6ea393d861b92165402f (patch) | |
tree | 91e00b94f4e3fc4c43460e771f672b67b22f6a5f /lib/content_encoding.c | |
parent | a0f3eaf25dd2c4acf1f49d28d5de4f1765521709 (diff) | |
download | curl-58d7cd28a0d8306c91be6ea393d861b92165402f.tar.gz |
brotli: data at the end of content can be lost
Decoding loop implementation did not concern the case when all
received data is consumed by Brotli decoder and the size of decoded
data internally hold by Brotli decoder is greater than CURL_MAX_WRITE_SIZE.
For content with unencoded length greater than CURL_MAX_WRITE_SIZE this
can result in the loss of data at the end of content.
Closes #2194
Diffstat (limited to 'lib/content_encoding.c')
-rw-r--r-- | lib/content_encoding.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/content_encoding.c b/lib/content_encoding.c index 01a155246..46bef0ca9 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -640,6 +640,7 @@ static CURLcode brotli_unencode_write(struct connectdata *conn, uint8_t *dst; size_t dstleft; CURLcode result = CURLE_OK; + BrotliDecoderResult r = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT; if(!bp->br) return CURLE_WRITE_ERROR; /* Stream already ended. */ @@ -648,9 +649,8 @@ static CURLcode brotli_unencode_write(struct connectdata *conn, if(!decomp) return CURLE_OUT_OF_MEMORY; - while(nbytes && result == CURLE_OK) { - BrotliDecoderResult r; - + while((nbytes || r == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) && + result == CURLE_OK) { dst = (uint8_t *) decomp; dstleft = DSIZ; r = BrotliDecoderDecompressStream(bp->br, |