- out_len = WRITEBUFFER_LEN - My_Connections[Idx].wdatalen - out->avail_out;
- My_Connections[Idx].wdatalen += out_len;
- My_Connections[Idx].bytes_out += out_len;
- My_Connections[Idx].zip.bytes_out += My_Connections[Idx].zip.wdatalen;
- My_Connections[Idx].zip.wdatalen = 0;
+ if (out->avail_out <= 0) {
+ /* Not all data was compressed, because data became
+ * bigger while compressing it. */
+ Log(LOG_ALERT, "Compression error: buffer overflow!?");
+ Conn_Close(Idx, "Compression error!", NULL, false);
+ return false;
+ }
+
+ assert(out->avail_out <= WRITEBUFFER_SLINK_LEN);
+
+ zipbuf_used = WRITEBUFFER_SLINK_LEN - out->avail_out;
+#if DEBUG_ZIP
+ Log(LOG_DEBUG, "zipbuf_used: %d", zipbuf_used);
+#endif
+ if (!array_catb(&My_Connections[Idx].wbuf,
+ (char *)zipbuf, (size_t) zipbuf_used)) {
+ Log (LOG_ALERT, "Compression error: can't copy data!?");
+ Conn_Close(Idx, "Compression error!", NULL, false);
+ return false;
+ }
+
+ My_Connections[Idx].bytes_out += zipbuf_used;
+ My_Connections[Idx].zip.bytes_out += array_bytes(&My_Connections[Idx].zip.wbuf);
+ array_trunc(&My_Connections[Idx].zip.wbuf);