From d5c88ebab3293658f0c1ac331a868227e9353fa4 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Fri, 22 Jan 2016 14:51:05 +0100 Subject: [PATCH 1/2] 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; From ecceec8e1a9771499931f9ff33518174875ce16f Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Fri, 22 Jan 2016 15:06:55 +0100 Subject: [PATCH 2/2] Tabs -> spaces fix --- SharpCompress/Compressor/Deflate/Inflate.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SharpCompress/Compressor/Deflate/Inflate.cs b/SharpCompress/Compressor/Deflate/Inflate.cs index dcfcddbf..587a69aa 100644 --- a/SharpCompress/Compressor/Deflate/Inflate.cs +++ b/SharpCompress/Compressor/Deflate/Inflate.cs @@ -895,11 +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; - + // 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; @@ -1003,10 +1003,10 @@ 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; + // 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;