mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-14 16:58:30 +00:00
Fix successful decompress reported as Error::Read (#1612)
* Fix successful decompress reported as Error::Read Streams less than 4096 bytes are sometimes reported as failed reads because stream_.avail_in is not reduced to 0. The next iteration of the loop finds `prev_avail_in == strm_.avail_in` and return false. `ret = inflate(...)` returns Z_STREAM_END on the first iteration of the loop indicating that inflate is finished. This fix prevents the second iteration of the loop from failing. * Fix successful decompress reported as Error::Read - Add unit tests for raw deflate that illustrates the decompression failure when there are extra trailing bytes
This commit is contained in:
parent
52d8dd41f1
commit
ee625232a4
2 changed files with 54 additions and 5 deletions
|
@ -3384,16 +3384,12 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
|
|||
data += strm_.avail_in;
|
||||
|
||||
std::array<char, CPPHTTPLIB_COMPRESSION_BUFSIZ> buff{};
|
||||
while (strm_.avail_in > 0) {
|
||||
while (strm_.avail_in > 0 && ret == Z_OK) {
|
||||
strm_.avail_out = static_cast<uInt>(buff.size());
|
||||
strm_.next_out = reinterpret_cast<Bytef *>(buff.data());
|
||||
|
||||
auto prev_avail_in = strm_.avail_in;
|
||||
|
||||
ret = inflate(&strm_, Z_NO_FLUSH);
|
||||
|
||||
if (prev_avail_in - strm_.avail_in == 0) { return false; }
|
||||
|
||||
assert(ret != Z_STREAM_ERROR);
|
||||
switch (ret) {
|
||||
case Z_NEED_DICT:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue