Skip to content

Commit 9f2e4ac

Browse files
committed
Add tests to ensure unused_data behaves correctly when using a raw_deflate igzipdecompressor on gzip or zlib data.
1 parent 1c2dc24 commit 9f2e4ac

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tests/test_igzip_lib.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
20-
20+
import gzip
2121
import itertools
2222
import os
2323
import pickle
24+
import zlib
2425
from typing import NamedTuple
2526

2627
from isal import igzip_lib
@@ -43,6 +44,8 @@ class Flag(NamedTuple):
4344

4445

4546
DATA = RAW_DATA[:128 * 1024]
47+
ZLIB_COMPRESSED = zlib.compress(DATA)
48+
GZIP_COMPRESSED = gzip.compress(DATA)
4649

4750
COMPRESS_LEVELS = list(range(4))
4851
HIST_BITS = list(range(16))
@@ -223,3 +226,29 @@ def test_failure(self):
223226
# Make sure there are no internal consistencies
224227
with pytest.raises(Exception):
225228
igzd.decompress(self.BAD_DATA * 30)
229+
230+
231+
@pytest.mark.parametrize("test_offset", range(5))
232+
def test_igzip_decompressor_raw_deflate_unused_data_zlib(test_offset):
233+
data = zlib.compress(b"bla")
234+
no_header = data[2:]
235+
trailer = data[-4:]
236+
raw_deflate_incomplete_trailer = no_header[:-test_offset]
237+
true_unused_data = trailer[:-test_offset]
238+
igzd = IgzipDecompressor(flag=DECOMP_DEFLATE)
239+
igzd.decompress(raw_deflate_incomplete_trailer)
240+
if igzd.eof:
241+
assert igzd.unused_data == true_unused_data
242+
243+
244+
@pytest.mark.parametrize("test_offset", range(9))
245+
def test_igzip_decompressor_raw_deflate_unused_data_gzip(test_offset):
246+
data = gzip.compress(b"bla")
247+
no_header = data[10:]
248+
trailer = data[-8:]
249+
raw_deflate_incomplete_trailer = no_header[:-test_offset]
250+
true_unused_data = trailer[:-test_offset]
251+
igzd = IgzipDecompressor(flag=DECOMP_DEFLATE)
252+
igzd.decompress(raw_deflate_incomplete_trailer)
253+
if igzd.eof:
254+
assert igzd.unused_data == true_unused_data

0 commit comments

Comments
 (0)