commit 0b51255: [Fix] Try to fix unzip function
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Sep 9 11:28:03 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-09-09 12:25:31 +0100
URL: https://github.com/rspamd/rspamd/commit/0b51255f334ced4362257fc2c93a48489c2ec55e (HEAD -> master)
[Fix] Try to fix unzip function
---
src/libutil/util.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/libutil/util.c b/src/libutil/util.c
index deba3e807..d3c4721bd 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -2295,21 +2295,20 @@ rspamd_fstring_gunzip(rspamd_fstring_t **in)
gsize total_out = 0;
do {
- strm.next_out = out->str;
- strm.avail_out = out->allocated;
+ strm.next_out = out->str + total_out;
+ strm.avail_out = out->allocated - total_out;
ret = inflate(&strm, Z_NO_FLUSH);
if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
break;
}
- gsize out_size = out->allocated - strm.avail_out;
- if (total_out + out_size > out->allocated) {
- out = rspamd_fstring_grow(out, total_out + out_size);
+ gsize out_remain = strm.avail_out;
+ total_out = out->allocated - out_remain;
+ if (out_remain == 0 && ret != Z_STREAM_END) {
+ out = rspamd_fstring_grow(out, out->allocated * 2);
}
- total_out += out_size;
-
} while (ret != Z_STREAM_END);
if (ret == Z_STREAM_END) {
More information about the Commits
mailing list