]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: test-compression - Add test for tiny invalid data
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 6 Jul 2020 11:54:48 +0000 (14:54 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 30 Jul 2020 14:26:36 +0000 (17:26 +0300)
Ensure compression handlers return EINVAL when reading
less than header size data.

src/lib-compression/test-compression.c

index 97a42a9fa926ce6ecc7c6bb646f569d800e8f47f..9b38b92b15ebb5f76ebc4aa69ce9714ac4dbdaa7 100644 (file)
@@ -574,6 +574,23 @@ static void test_compression_handler_errors(const struct compression_handler *ha
        test_assert(input->stream_errno == EPIPE);
        i_stream_unref(&input);
 
+       /* Cannot do the next check if we don't know if it's compressed. */
+       if (handler->is_compressed != NULL) {
+               /* test incrementally reading up to 32 bytes of plaintext data
+                  that should not match any handlers' header */
+               for (size_t i = 0; i < 32; i++) {
+                       is = test_istream_create_data("dededededededededededededededede", i);
+                       input = handler->create_istream(is, FALSE);
+                       i_stream_unref(&is);
+                       while (i_stream_read_more(input, &data, &size) >= 0) {
+                               test_assert_idx(size == 0, i);
+                               i_stream_skip(input, size);
+                       }
+                       test_assert_idx(input->stream_errno == EINVAL, i);
+                       i_stream_unref(&input);
+               }
+       }
+
        test_end();
 }