mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 17:31:46 -05:00
content_encoding: fix inflate_stream for no bytes available
- Don't call zlib's inflate() when avail_in stream bytes is 0. This is a follow up to the parent commit 19e66e5. Prior to that change libcurl's inflate_stream could call zlib's inflate even when no bytes were available, causing inflate to return Z_BUF_ERROR, and then inflate_stream would treat that as a hard error and return CURLE_BAD_CONTENT_ENCODING. According to the zlib FAQ, Z_BUF_ERROR is not fatal. This bug would happen randomly since packet sizes are arbitrary. A test of 10,000 transfers had 55 fail (ie 0.55%). Ref: https://zlib.net/zlib_faq.html#faq05 Closes https://github.com/curl/curl/pull/2060
This commit is contained in:
parent
19e66e5362
commit
fa64b0fc4b
@ -139,6 +139,11 @@ inflate_stream(struct connectdata *conn, contenc_writer *writer)
|
|||||||
/* because the buffer size is fixed, iteratively decompress and transfer to
|
/* because the buffer size is fixed, iteratively decompress and transfer to
|
||||||
the client via client_write. */
|
the client via client_write. */
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
if(z->avail_in == 0) {
|
||||||
|
free(decomp);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* (re)set buffer for decompressed output for every iteration */
|
/* (re)set buffer for decompressed output for every iteration */
|
||||||
z->next_out = (Bytef *) decomp;
|
z->next_out = (Bytef *) decomp;
|
||||||
z->avail_out = DSIZ;
|
z->avail_out = DSIZ;
|
||||||
@ -163,10 +168,7 @@ inflate_stream(struct connectdata *conn, contenc_writer *writer)
|
|||||||
/* Done with these bytes, exit */
|
/* Done with these bytes, exit */
|
||||||
|
|
||||||
/* status is always Z_OK at this point! */
|
/* status is always Z_OK at this point! */
|
||||||
if(z->avail_in == 0) {
|
continue;
|
||||||
free(decomp);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(allow_restart && status == Z_DATA_ERROR) {
|
else if(allow_restart && status == Z_DATA_ERROR) {
|
||||||
/* some servers seem to not generate zlib headers, so this is an attempt
|
/* some servers seem to not generate zlib headers, so this is an attempt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user