Skip to content

Commit

Permalink
Add back-and-forth inflateCopy() test
Browse files Browse the repository at this point in the history
Check that calling inflateCopy() twice does not result in memory
corruption.
  • Loading branch information
iii-i committed May 21, 2024
1 parent 4a99dd0 commit dc1325c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/test_inflate_copy.cc
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

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);
}

0 comments on commit dc1325c

Please sign in to comment.