ZlibStream fails to check checksum correctly #239

Open
opened 2026-01-29 22:08:52 +00:00 by claunia · 0 comments
Owner

Originally created by @ied206 on GitHub (Sep 15, 2017).

ZlibStreams occasionally fails to decompress correct zlib files.

.zz files in TestSample.zip are the zlib streams which causes ZlibStream to malfunction.
When ZlibStream tries to decompress those files, it throws ZlibException with 'invalid data check' message.

However, those files can be successfully extracted in pigz with --zlib flag, so the problem resides in SharpCompress.

To prove this, I converted zlib streams into pure deflate streams by removing first 2 byte (zlib magic number) and last 4 byte (Adler32 checksum), and tried to decompress with DeflateStream. In this case, file was successfully decompressed, so I suspect SharpCompress' Adler32 checksum checking routine is faulty.

I wrote some Tests to help debugging, please have a look.

Tested Environment

OS : Windows 10 x64 v1703
IDE : Visual Studio 2017
DotNet : .Net Framework 4.6.2, .Net Framework 4.7
Package : SharpCompress 0.18.1

Originally created by @ied206 on GitHub (Sep 15, 2017). ZlibStreams occasionally fails to decompress correct zlib files. .zz files in [TestSample.zip](https://github.com/adamhathcock/sharpcompress/files/1307402/TestSample.zip) are the zlib streams which causes ZlibStream to malfunction. When ZlibStream tries to decompress those files, it throws ZlibException with 'invalid data check' message. However, those files can be successfully extracted in [pigz](https://zlib.net/pigz/) with --zlib flag, so the problem resides in SharpCompress. To prove this, I converted zlib streams into pure deflate streams by removing first 2 byte (zlib magic number) and last 4 byte (Adler32 checksum), and tried to decompress with DeflateStream. In this case, file was successfully decompressed, so I suspect SharpCompress' Adler32 checksum checking routine is faulty. I wrote some [Tests](https://github.com/ied206/SharpCompressBug) to help debugging, please have a look. ### Tested Environment OS : Windows 10 x64 v1703 IDE : Visual Studio 2017 DotNet : .Net Framework 4.6.2, .Net Framework 4.7 Package : SharpCompress 0.18.1
claunia added the bug label 2026-01-29 22:08:52 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#239