From 58d7cd28a0d8306c91be6ea393d861b92165402f Mon Sep 17 00:00:00 2001 From: Mikalai Ananenka Date: Tue, 26 Dec 2017 00:17:08 +0300 Subject: 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 --- lib/content_encoding.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') 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, -- cgit v1.2.3