From: Ilya Leoshkevich Date: Tue, 21 May 2024 10:45:39 +0000 (+0200) Subject: Add back-and-forth inflateCopy() test X-Git-Tag: 2.2.0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af7c6cad18b47d7673af2c46a89ac7e3d5b1710e;p=thirdparty%2Fzlib-ng.git Add back-and-forth inflateCopy() test Check that calling inflateCopy() twice does not result in memory corruption. --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 03935fab..3f0d023e 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 00000000..02eea264 --- /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); +}