From d5c88ebab3293658f0c1ac331a868227e9353fa4 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Fri, 22 Jan 2016 14:51:05 +0100 Subject: [PATCH] Bugfix for inflate algorithm cutting of the end of certain blocks --- SharpCompress/Compressor/Deflate/Inflate.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SharpCompress/Compressor/Deflate/Inflate.cs b/SharpCompress/Compressor/Deflate/Inflate.cs index c4f0889b..dcfcddbf 100644 --- a/SharpCompress/Compressor/Deflate/Inflate.cs +++ b/SharpCompress/Compressor/Deflate/Inflate.cs @@ -895,6 +895,11 @@ namespace SharpCompress.Compressor.Deflate r = ZlibConstants.Z_OK; else { + // Handling missing trailing bit(s) + var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k]))*3; + if (k >= tree[tmp_tindex + 1]) + break; + blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n; @@ -998,6 +1003,11 @@ namespace SharpCompress.Compressor.Deflate r = ZlibConstants.Z_OK; else { + // Handling missing trailing bit(s) + var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k]))*3; + if (k >= tree[tmp_tindex + 1]) + break; + blocks.bitb = b; blocks.bitk = k; z.AvailableBytesIn = n;