summaryrefslogtreecommitdiff
path: root/neozip/test/test_inflate_sync.cc
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:09 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:09 +0300
commit7fb132859fda54aa96bc9dd46d302b343eeb5a02 (patch)
treeb43ae77d7451fb470a260c03349a1caf2846c5e5 /neozip/test/test_inflate_sync.cc
parentb1e34e861b5d732afe828d58aad2c638135061fd (diff)
parentc2712b8a345191f6ed79558c089777df94590087 (diff)
downloadProject-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.tar.gz
Project-Tick-7fb132859fda54aa96bc9dd46d302b343eeb5a02.zip
Add 'neozip/' from commit 'c2712b8a345191f6ed79558c089777df94590087'
git-subtree-dir: neozip git-subtree-mainline: b1e34e861b5d732afe828d58aad2c638135061fd git-subtree-split: c2712b8a345191f6ed79558c089777df94590087
Diffstat (limited to 'neozip/test/test_inflate_sync.cc')
-rw-r--r--neozip/test/test_inflate_sync.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/neozip/test/test_inflate_sync.cc b/neozip/test/test_inflate_sync.cc
new file mode 100644
index 0000000000..a79d867e68
--- /dev/null
+++ b/neozip/test/test_inflate_sync.cc
@@ -0,0 +1,75 @@
+/* test_inflate_sync.cc - Test inflateSync using full flush deflate and corrupted data */
+
+#include "zbuild.h"
+#ifdef ZLIB_COMPAT
+# include "zlib.h"
+#else
+# include "zlib-ng.h"
+#endif
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "test_shared.h"
+
+#include <gtest/gtest.h>
+
+TEST(inflate, sync) {
+ PREFIX3(stream) c_stream, d_stream;
+ uint8_t compr[128], uncompr[128];
+ z_size_t compr_len = sizeof(compr), uncompr_len = sizeof(uncompr);
+ int err;
+
+ memset(&c_stream, 0, sizeof(c_stream));
+
+ /* build compressed stream with full flush */
+ err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
+ EXPECT_EQ(err, Z_OK);
+
+ c_stream.next_in = (z_const unsigned char *)hello;
+ c_stream.next_out = compr;
+ c_stream.avail_in = 3;
+ c_stream.avail_out = (uint32_t)compr_len;
+
+ err = PREFIX(deflate)(&c_stream, Z_FULL_FLUSH);
+ EXPECT_EQ(err, Z_OK);
+
+ /* force an error in first compressed block */
+ compr[3]++;
+ c_stream.avail_in = hello_len-3;
+
+ err = PREFIX(deflate)(&c_stream, Z_FINISH);
+ EXPECT_EQ(err, Z_STREAM_END);
+
+ err = PREFIX(deflateEnd)(&c_stream);
+ EXPECT_EQ(err, Z_OK);
+
+ compr_len = (z_size_t)c_stream.total_out;
+
+ memset(&d_stream, 0, sizeof(d_stream));
+ /* just read the zlib header */
+ d_stream.next_in = compr;
+ d_stream.avail_in = 2;
+
+ err = PREFIX(inflateInit)(&d_stream);
+ EXPECT_EQ(err, Z_OK);
+
+ d_stream.next_out = uncompr;
+ d_stream.avail_out = (uint32_t)uncompr_len;
+
+ err = PREFIX(inflate)(&d_stream, Z_NO_FLUSH);
+ EXPECT_EQ(err, Z_OK);
+
+ /* read all compressed data, but skip damaged part */
+ d_stream.avail_in = (uint32_t)compr_len-2;
+ err = PREFIX(inflateSync)(&d_stream);
+ EXPECT_EQ(err, Z_OK);
+
+ err = PREFIX(inflate)(&d_stream, Z_FINISH);
+ EXPECT_EQ(err, Z_STREAM_END);
+
+ err = PREFIX(inflateEnd)(&d_stream);
+ EXPECT_EQ(err, Z_OK);
+}