From: Aki Tuomi Date: Fri, 12 Jun 2026 11:19:42 +0000 (+0000) Subject: [PATCH 4/4] lib-compression: test - Add zero-len frame test for all handlers X-Git-Tag: archive/raspbian/1%2.4.1+dfsg1-6+rpi1+deb13u7^2~93 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ab58857b86c8508e147bb73f5284b24b0945a633;p=dovecot.git [PATCH 4/4] lib-compression: test - Add zero-len frame test for all handlers Verify that successive empty compressed frames produce a clean EOF across all compression algorithms. lz4 is limited to one frame as it uses a custom single-stream format without concatenation support. Gbp-Pq: Name 0004-lib-compression-test-Add-zero-len-frame-test-for-all.patch --- diff --git a/src/lib-compression/test-compression.c b/src/lib-compression/test-compression.c index a75d29b..e035abf 100644 --- a/src/lib-compression/test-compression.c +++ b/src/lib-compression/test-compression.c @@ -154,6 +154,46 @@ test_compression_handler_empty(const struct compression_handler *handler, test_end(); } +static void +test_compression_handler_zero_frame(const struct compression_handler *handler, + bool autodetect) +{ + test_begin(t_strdup_printf("compression handler %s (zero-len frame, autodetect=%s)", + handler->name, autodetect ? "yes" : "no")); + + /* Produce successive empty frames. Each frame needs its own ostream + because o_stream_finish() propagates to the parent; compress each + into a separate buffer then concatenate. + lz4 uses a custom single-stream format and does not support + concatenated frames, so limit it to one. */ + unsigned int n_frames = strcmp(handler->name, "lz4") == 0 ? 1 : 3; + buffer_t *compressed = buffer_create_dynamic(pool_datastack_create(), 256); + for (unsigned int i = 0; i < n_frames; i++) { + buffer_t *frame_buf = buffer_create_dynamic(pool_datastack_create(), 64); + struct ostream *os = test_ostream_create(frame_buf); + struct ostream *output = handler->create_ostream_auto(os, set.event); + o_stream_unref(&os); + test_assert_idx(o_stream_finish(output) == 1, i); + o_stream_unref(&output); + test_assert_idx(frame_buf->used > 0, i); + buffer_append(compressed, frame_buf->data, frame_buf->used); + } + + /* Decompress: must yield clean EOF with no error and no loop. */ + struct istream *is = test_istream_create_data(compressed->data, compressed->used); + is->blocking = TRUE; + struct istream *input = !autodetect ? handler->create_istream(is) : + i_stream_create_decompress(is, 0); + i_stream_unref(&is); + + test_assert(i_stream_read(input) == -1); + test_assert(input->eof); + test_assert(input->stream_errno == 0); + i_stream_unref(&input); + + test_end(); +} + static void test_compression_handler_seek(const struct compression_handler *handler, bool autodetect) @@ -743,6 +783,7 @@ static void test_compression_int(bool autodetect) test_compression_handler_detect(&compression_handlers[i]); test_compression_handler_short(&compression_handlers[i], autodetect); test_compression_handler_empty(&compression_handlers[i], autodetect); + test_compression_handler_zero_frame(&compression_handlers[i], autodetect); test_compression_handler(&compression_handlers[i], autodetect); test_compression_handler_seek(&compression_handlers[i], autodetect); test_compression_handler_reset(&compression_handlers[i], autodetect);