8000 Reset the stream checksum in mz_deflateReset by astunm · Pull Request #400 · richgel999/miniz · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
1 chang 8000 e: 1 addition & 0 deletions miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree))
return MZ_STREAM_ERROR;
pStream->total_in = pStream->total_out = 0;
pStream->adler = MZ_ADLER32_INIT;
tdefl_init((tdefl_compressor *)pStream->state, NULL, NULL, ((tdefl_compressor *)pStream->state)->m_flags);
return MZ_OK;
}
Expand Down
30 changes: 30 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,36 @@ TEST_CASE("Zip reader zip64 local header offset out of boun 8000 ds")
mz_zip_reader_end(&zip);
}

TEST_CASE("Deflate reset restores the initial checksum")
{
const mz_uint8 input[] = "reset checksum";
mz_uint8 compressed[128], uncompressed[sizeof(input)];
mz_stream stream = {};
REQUIRE(mz_deflateInit(&stream, MZ_DEFAULT_COMPRESSION) == MZ_OK);

for (int i = 0; i < 2; ++i)
{
stream.next_in = input;
stream.avail_in = sizeof(input);
stream.next_out = compressed;
stream.avail_out = sizeof(compressed);
REQUIRE(mz_deflate(&stream, MZ_FINISH) == MZ_STREAM_END);
REQUIRE(stream.adler == mz_adler32(MZ_ADLER32_INIT, input, sizeof(input)));

mz_ulong uncompressed_size = sizeof(uncompressed);
REQUIRE(mz_uncompress(uncompressed, &uncompressed_size, compressed, stream.total_out) == MZ_OK);
REQUIRE(uncompressed_size == sizeof(input));
REQUIRE(memcmp(uncompressed, input, sizeof(input)) == 0);

REQUIRE(mz_deflateReset(&stream) == MZ_OK);
CHECK(stream.adler == MZ_ADLER32_INIT);
CHECK(stream.total_in == 0);
CHECK(stream.total_out == 0);
}

REQUIRE(mz_deflateEnd(&stream) == MZ_OK);
}

TEST_CASE("Tinfl / tdefl tests")
{
SECTION("simple_test1")
Expand Down
Loading
0