From: Vsevolod Stakhov Date: Tue, 20 Feb 2018 19:12:44 +0000 (+0000) Subject: [Minor] Use suggested method to allocate deflate out buffer X-Git-Tag: 1.7.0~160 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c89bf0be8e9ffff2bc9fc3f53bd2edf7bd4a6c42;p=thirdparty%2Frspamd.git [Minor] Use suggested method to allocate deflate out buffer --- diff --git a/src/libutil/util.c b/src/libutil/util.c index d1500b54a5..c8de9a6512 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -2810,7 +2810,7 @@ rspamd_fstring_gzip (rspamd_fstring_t **in) return FALSE; } - comp = rspamd_fstring_sized_new (MIN (buf->len, 32768)); + comp = rspamd_fstring_sized_new (deflateBound (&strm, buf->len)); strm.avail_in = buf->len; strm.next_in = (guchar *)buf->str; @@ -2823,7 +2823,7 @@ rspamd_fstring_gzip (rspamd_fstring_t **in) rc = deflate (&strm, Z_FINISH); - if (rc != Z_OK) { + if (rc != Z_OK && rc != Z_BUF_ERROR) { if (rc == Z_STREAM_END) { break; } @@ -2840,8 +2840,7 @@ rspamd_fstring_gzip (rspamd_fstring_t **in) if (strm.avail_out == 0 && strm.avail_in != 0) { /* Need to allocate more */ remain = comp->len; - comp = rspamd_fstring_grow (comp, comp->allocated + - strm.avail_in + 10); + comp = rspamd_fstring_grow (comp, strm.avail_in); p = comp->str + remain; remain = comp->allocated - remain; }