From af7c6cad18b47d7673af2c46a89ac7e3d5b1710e Mon Sep 17 00:00:00 2001 From: Ilya Leoshkevich Date: Tue, 21 May 2024 12:45:39 +0200 Subject: [PATCH] Add back-and-forth inflateCopy() test Check that calling inflateCopy() twice does not result in memory corruption. --- test/CMakeLists.txt | 1 + test/test_inflate_copy.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/test_inflate_copy.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 03935fab4d..3f0d023eb0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -175,6 +175,7 @@ if(WITH_GTEST) test_deflate_tune.cc test_dict.cc test_inflate_adler32.cc + test_inflate_copy.cc test_large_buffers.cc test_raw.cc test_small_buffers.cc diff --git a/test/test_inflate_copy.cc b/test/test_inflate_copy.cc new file mode 100644 index 0000000000..02eea2648a --- /dev/null +++ b/test/test_inflate_copy.cc @@ -0,0 +1,31 @@ +/* test_inflate_copy.cc - Test copying inflate stream */ + +#include "zbuild.h" +#ifdef ZLIB_COMPAT +# include "zlib.h" +#else +# include "zlib-ng.h" +#endif + +#include "test_shared.h" + +#include + +TEST(inflate, copy_back_and_forth) { + PREFIX3(stream) d1_stream, d2_stream; + int err; + + memset(&d1_stream, 0, sizeof(d1_stream)); + err = PREFIX(inflateInit2)(&d1_stream, MAX_WBITS + 14); + ASSERT_EQ(err, Z_OK); + err = PREFIX(inflateCopy)(&d2_stream, &d1_stream); + ASSERT_EQ(err, Z_OK); + err = PREFIX(inflateEnd)(&d1_stream); + ASSERT_EQ(err, Z_OK); + err = PREFIX(inflateCopy)(&d1_stream, &d2_stream); + ASSERT_EQ(err, Z_OK); + err = PREFIX(inflateEnd)(&d1_stream); + ASSERT_EQ(err, Z_OK); + err = PREFIX(inflateEnd)(&d2_stream); + ASSERT_EQ(err, Z_OK); +}