naccyde / rpms / systemd

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