richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
4cad4c
From fc1e6209f622ff96c24259a50d98ca6f57a55426 Mon Sep 17 00:00:00 2001
4cad4c
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
4cad4c
Date: Mon, 29 Oct 2018 22:21:28 +0100
4cad4c
Subject: [PATCH] test-compress: add test for short decompress_startswith calls
4cad4c
4cad4c
I thought this might fail with lz4 < 1.8.3, but it seems that because of
4cad4c
greedy_realloc, we always use a buffer that is large enough, and it always
4cad4c
passes.
4cad4c
4cad4c
(cherry picked from commit ba17efce44e6a1e139c1671205e9a6ed3824af1b)
4cad4c
Resolves: #1843871
4cad4c
---
4cad4c
 src/journal/test-compress.c | 32 ++++++++++++++++++++++++++++++++
4cad4c
 1 file changed, 32 insertions(+)
4cad4c
4cad4c
diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
4cad4c
index eb3dc3eb6b..65cd3fbfeb 100644
4cad4c
--- a/src/journal/test-compress.c
4cad4c
+++ b/src/journal/test-compress.c
4cad4c
@@ -131,6 +131,32 @@ static void test_decompress_startswith(int compression,
4cad4c
         assert_se(r > 0);
4cad4c
 }
4cad4c
 
4cad4c
+static void test_decompress_startswith_short(int compression,
4cad4c
+                                             compress_blob_t compress,
4cad4c
+                                             decompress_sw_t decompress_sw) {
4cad4c
+
4cad4c
+#define TEXT "HUGE=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
4cad4c
+
4cad4c
+        char buf[1024];
4cad4c
+        size_t i, csize;
4cad4c
+        int r;
4cad4c
+
4cad4c
+        log_info("/* %s with %s */", __func__, object_compressed_to_string(compression));
4cad4c
+
4cad4c
+        r = compress(TEXT, sizeof TEXT, buf, sizeof buf, &csize);
4cad4c
+        assert_se(r == 0);
4cad4c
+
4cad4c
+        for (i = 1; i < strlen(TEXT); i++) {
4cad4c
+                size_t alloc_size = i;
4cad4c
+                _cleanup_free_ void *buf2 = NULL;
4cad4c
+
4cad4c
+                assert_se(buf2 = malloc(i));
4cad4c
+
4cad4c
+                assert_se(decompress_sw(buf, csize, &buf2, &alloc_size, TEXT, i, TEXT[i]) == 1);
4cad4c
+                assert_se(decompress_sw(buf, csize, &buf2, &alloc_size, TEXT, i, 'y') == 0);
4cad4c
+        }
4cad4c
+}
4cad4c
+
4cad4c
 static void test_compress_stream(int compression,
4cad4c
                                  const char* cat,
4cad4c
                                  compress_stream_t compress,
4cad4c
@@ -271,6 +297,9 @@ int main(int argc, char *argv[]) {
4cad4c
 
4cad4c
         test_compress_stream(OBJECT_COMPRESSED_XZ, "xzcat",
4cad4c
                              compress_stream_xz, decompress_stream_xz, srcfile);
4cad4c
+
4cad4c
+        test_decompress_startswith_short(OBJECT_COMPRESSED_XZ, compress_blob_xz, decompress_startswith_xz);
4cad4c
+
4cad4c
 #else
4cad4c
         log_info("/* XZ test skipped */");
4cad4c
 #endif
4cad4c
@@ -295,6 +324,9 @@ int main(int argc, char *argv[]) {
4cad4c
                              compress_stream_lz4, decompress_stream_lz4, srcfile);
4cad4c
 
4cad4c
         test_lz4_decompress_partial();
4cad4c
+
4cad4c
+        test_decompress_startswith_short(OBJECT_COMPRESSED_LZ4, compress_blob_lz4, decompress_startswith_lz4);
4cad4c
+
4cad4c
 #else
4cad4c
         log_info("/* LZ4 test skipped */");
4cad4c
 #endif