]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: Don't calculate crc32 if using zlib in deflate mode
authorMichael M Slusarz <michael.slusarz@open-xchange.com>
Sat, 4 Oct 2025 18:04:31 +0000 (12:04 -0600)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sat, 18 Oct 2025 17:49:23 +0000 (17:49 +0000)
src/lib-compression/istream-zlib.c
src/lib-compression/ostream-zlib.c

index f5513747244802967feb100254900edad496f987..93b3473071d86e338c1a2a9caba45068963f2c7e 100644 (file)
@@ -264,9 +264,11 @@ static ssize_t i_stream_zlib_read(struct istream_private *stream)
        ret = inflate(&zstream->zs, Z_SYNC_FLUSH);
 
        out_size -= zstream->zs.avail_out;
-       zstream->crc32 = crc32_data_more(zstream->crc32,
-                                        stream->w_buffer + stream->pos,
-                                        out_size);
+       /* CRC32 is only needed for GZ trailer. */
+       if (zstream->gz)
+               zstream->crc32 = crc32_data_more(zstream->crc32,
+                                                stream->w_buffer + stream->pos,
+                                                out_size);
        stream->pos += out_size;
 
        size_t bytes_consumed = size - zstream->zs.avail_in;
index 5cc22157376f01f5b5410d2b53b95c212366abe7..ed41f5054f14248a9e35dc00b54ad42cf6a2b540 100644 (file)
@@ -228,7 +228,9 @@ o_stream_zlib_send_chunk(struct zlib_ostream *zstream,
        }
        size -= zs->avail_in;
 
-       zstream->crc = crc32_data_more(zstream->crc, data, size);
+       /* CRC32 is only needed for GZ trailer. */
+       if (zstream->gz)
+               zstream->crc = crc32_data_more(zstream->crc, data, size);
        zstream->bytes32 += size;
        zstream->flushed = FALSE;
        return size;