From 456369476a0f8a7599c27843607441d2698f16d9 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 22 Mar 2025 13:08:37 +0100 Subject: [PATCH] Fix zlib decompression --- src/common/utils/compression.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/common/utils/compression.cpp b/src/common/utils/compression.cpp index aa4ab0be..15cbbc04 100644 --- a/src/common/utils/compression.cpp +++ b/src/common/utils/compression.cpp @@ -57,32 +57,25 @@ namespace utils::compression return {}; } - int ret{}; - size_t offset = 0; static thread_local std::array dest{}; auto& stream = stream_container.get(); + stream.avail_in = static_cast(data.size()); + stream.next_in = reinterpret_cast(data.data()); + do { - const auto input_size = std::min(dest.size(), data.size() - offset); - stream.avail_in = static_cast(input_size); - stream.next_in = reinterpret_cast(data.data()) + offset; - offset += stream.avail_in; + stream.avail_out = static_cast(dest.size()); + stream.next_out = dest.data(); - do + const auto ret = inflate(&stream, Z_FINISH); + if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_STREAM_END) { - stream.avail_out = static_cast(dest.size()); - stream.next_out = dest.data(); + return {}; + } - ret = inflate(&stream, Z_NO_FLUSH); - if (ret != Z_OK && ret != Z_STREAM_END) - { - return {}; - } - - buffer.insert(buffer.end(), dest.data(), dest.data() + dest.size() - stream.avail_out); - } while (stream.avail_out == 0); - } while (ret != Z_STREAM_END); + buffer.insert(buffer.end(), dest.data(), dest.data() + dest.size() - stream.avail_out); + } while (stream.avail_out == 0); return buffer; }