mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
ZlibStream fails to check checksum correctly #241
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
@ied206 commented on GitHub (Sep 16, 2017):
More addtional information, I checked the internal adler32 checksum in InflateBlocks.Process().
ex1_zlib_sharpcompress.jpg.zz
ex2_zlib_sharpcompress.jpg.zz
So only the high two bytes are miscalculated.
@adamhathcock commented on GitHub (Sep 17, 2017):
Fixed by https://github.com/adamhathcock/sharpcompress/pull/301