Skip to content

Commit 9b2556a

Browse files
committed
Add tests to reproduce bug where openening with a wrong compresslevel in read mode causes a crash.
1 parent 970c141 commit 9b2556a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/test_gzip_compliance.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ def test_with_open(self):
456456
else:
457457
self.fail("1/0 didn't raise an exception")
458458

459+
def test_read_and_compresslevel(self):
460+
with igzip.GzipFile(self.filename, "wb") as f:
461+
f.write(b"xxx")
462+
with igzip.GzipFile(self.filename, "rb", compresslevel=17) as f:
463+
data = f.read()
464+
assert data == b"xxx"
465+
459466
def test_zero_padded_file(self):
460467
with igzip.GzipFile(self.filename, "wb") as f:
461468
f.write(data1 * 50)
@@ -785,6 +792,13 @@ def test_newline(self):
785792
with igzip.open(self.filename, "rt", newline="\r") as f:
786793
self.assertEqual(f.readlines(), [uncompressed])
787794

795+
def test_reading_and_compresslevel(self):
796+
with igzip.open(self.filename, "wb") as f:
797+
f.write(data1)
798+
with igzip.open(self.filename, "rb", compresslevel=17) as f:
799+
text = f.read()
800+
assert text == data1
801+
788802

789803
def create_and_remove_directory(directory):
790804
def decorator(function):

tests/test_igzip_threaded.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,11 @@ def test_igzip_threaded_append_text_mode(tmp_path):
191191
with gzip.open(test_file, "rt") as f:
192192
contents = f.read()
193193
assert contents == "ABCD"
194+
195+
196+
def test_igzip_threaded_open_compresslevel_and_reading(tmp_path):
197+
test_file = tmp_path / "test.txt.gz"
198+
test_file.write_bytes(gzip.compress(b"thisisatest"))
199+
with igzip_threaded.open(test_file, compresslevel=5) as f:
200+
text = f.read()
201+
assert text == b"thisisatest"

0 commit comments

Comments
 (0)