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;
rc = deflate (&strm, Z_FINISH);
- if (rc != Z_OK) {
+ if (rc != Z_OK && rc != Z_BUF_ERROR) {
if (rc == Z_STREAM_END) {
break;
}
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;
}