|
| 1 | +From 589ecdc0783ef8877ae5210e41f29a2be65992e7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Stefan Eissing <stefan@eissing.org> |
| 3 | +Date: Thu, 28 Mar 2024 11:08:15 +0100 |
| 4 | +Subject: [PATCH] content_encoding: brotli and others, pass through 0-length |
| 5 | + writes |
| 6 | + |
| 7 | +- curl's transfer handling may write 0-length chunks at the end of the |
| 8 | + download with an EOS flag. (HTTP/2 does this commonly) |
| 9 | + |
| 10 | +- content encoders need to pass-through such a write and not count this |
| 11 | + as error in case they are finished decoding |
| 12 | + |
| 13 | +Fixes #13209 |
| 14 | +Fixes #13212 |
| 15 | +Closes #13219 |
| 16 | +--- |
| 17 | + lib/content_encoding.c | 10 +++++----- |
| 18 | + tests/http/test_02_download.py | 13 +++++++++++++ |
| 19 | + tests/http/testenv/env.py | 7 ++++++- |
| 20 | + tests/http/testenv/httpd.py | 20 ++++++++++++++++++++ |
| 21 | + 4 files changed, 44 insertions(+), 6 deletions(-) |
| 22 | + |
| 23 | +diff --git a/lib/content_encoding.c b/lib/content_encoding.c |
| 24 | +index c1abf24e8..8e926dd2e 100644 |
| 25 | +--- a/lib/content_encoding.c |
| 26 | ++++ b/lib/content_encoding.c |
| 27 | +@@ -300,7 +300,7 @@ static CURLcode deflate_do_write(struct Curl_easy *data, |
| 28 | + struct zlib_writer *zp = (struct zlib_writer *) writer; |
| 29 | + z_stream *z = &zp->z; /* zlib state structure */ |
| 30 | + |
| 31 | +- if(!(type & CLIENTWRITE_BODY)) |
| 32 | ++ if(!(type & CLIENTWRITE_BODY) || !nbytes) |
| 33 | + return Curl_cwriter_write(data, writer->next, type, buf, nbytes); |
| 34 | + |
| 35 | + /* Set the compressed input when this function is called */ |
| 36 | +@@ -457,7 +457,7 @@ static CURLcode gzip_do_write(struct Curl_easy *data, |
| 37 | + struct zlib_writer *zp = (struct zlib_writer *) writer; |
| 38 | + z_stream *z = &zp->z; /* zlib state structure */ |
| 39 | + |
| 40 | +- if(!(type & CLIENTWRITE_BODY)) |
| 41 | ++ if(!(type & CLIENTWRITE_BODY) || !nbytes) |
| 42 | + return Curl_cwriter_write(data, writer->next, type, buf, nbytes); |
| 43 | + |
| 44 | + if(zp->zlib_init == ZLIB_INIT_GZIP) { |
| 45 | +@@ -669,7 +669,7 @@ static CURLcode brotli_do_write(struct Curl_easy *data, |
| 46 | + CURLcode result = CURLE_OK; |
| 47 | + BrotliDecoderResult r = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT; |
| 48 | + |
| 49 | +- if(!(type & CLIENTWRITE_BODY)) |
| 50 | ++ if(!(type & CLIENTWRITE_BODY) || !nbytes) |
| 51 | + return Curl_cwriter_write(data, writer->next, type, buf, nbytes); |
| 52 | + |
| 53 | + if(!bp->br) |
| 54 | +@@ -762,7 +762,7 @@ static CURLcode zstd_do_write(struct Curl_easy *data, |
| 55 | + ZSTD_outBuffer out; |
| 56 | + size_t errorCode; |
| 57 | + |
| 58 | +- if(!(type & CLIENTWRITE_BODY)) |
| 59 | ++ if(!(type & CLIENTWRITE_BODY) || !nbytes) |
| 60 | + return Curl_cwriter_write(data, writer->next, type, buf, nbytes); |
| 61 | + |
| 62 | + if(!zp->decomp) { |
| 63 | +@@ -916,7 +916,7 @@ static CURLcode error_do_write(struct Curl_easy *data, |
| 64 | + (void) buf; |
| 65 | + (void) nbytes; |
| 66 | + |
| 67 | +- if(!(type & CLIENTWRITE_BODY)) |
| 68 | ++ if(!(type & CLIENTWRITE_BODY) || !nbytes) |
| 69 | + return Curl_cwriter_write(data, writer->next, type, buf, nbytes); |
| 70 | + |
| 71 | + failf(data, "Unrecognized content encoding type. " |
| 72 | +-- |
| 73 | +2.44.0.windows.1 |
| 74 | + |
0 commit comments