Skip to content

Commit 14ca34c

Browse files
authored
Merge pull request #43 from pycompression/release_0.4.3
Release 0.4.3
2 parents cb7e182 + 96424a2 commit 14ca34c

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ jobs:
6262
- "pypy-3.10"
6363
os: ["ubuntu-latest"]
6464
include:
65-
- os: "macos-latest" # For m1 macos
66-
python-version: "3.8"
67-
- os: "macos-13" # for x86 macos
65+
- os: "macos-14" # For m1 macos
66+
python-version: "3.12"
67+
- os: "macos-latest" # for x86 macos
6868
python-version: "3.8"
6969
- os: "windows-latest"
7070
python-version: "3.8"

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 0.4.3
11+
-----------------
12+
+ Fix a bug where files larger than 4GB could not be decompressed.
13+
1014
version 0.4.2
1115
-----------------
1216
+ Fix a reference counting error that happened on module initialization and

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def build_zlib_ng():
124124

125125
setup(
126126
name="zlib-ng",
127-
version="0.4.2",
127+
version="0.4.3",
128128
description="Drop-in replacement for zlib and gzip modules using zlib-ng",
129129
author="Leiden University Medical Center",
130130
author_email="[email protected]", # A placeholder for now

src/zlib_ng/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# This file is part of python-zlib-ng which is distributed under the
66
# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.
77

8-
__version__ = "0.4.2"
8+
__version__ = "0.4.3"

src/zlib_ng/zlib_ngmodule.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2590,8 +2590,9 @@ GzipReader_read_into_buffer(GzipReader *self, uint8_t *out_buffer, size_t out_bu
25902590
return -1;
25912591
}
25922592
uint32_t length = load_u32_le(current_pos);
2593-
current_pos += 4;
2594-
if (length != self->zst.total_out) {
2593+
current_pos += 4;
2594+
// ISIZE is the length of the original data modulo 2^32
2595+
if (length != (0xFFFFFFFFUL & self->zst.total_out)) {
25952596
Py_BLOCK_THREADS;
25962597
PyErr_SetString(BadGzipFile, "Incorrect length of data produced");
25972598
return -1;

tests/test_gzip_ng.py

+25
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,31 @@ def test_decompress_incorrect_length():
292292
error.match("Incorrect length of data produced")
293293

294294

295+
def test_decompress_on_long_input():
296+
# Ensure that a compressed payload with length bigger than 2**32 (ISIZE is
297+
# overflown) can be decompressed. To avoid writing the whole uncompressed payload
298+
# into memory, the test writes the compressed data in chunks. The payload consists
299+
# almost exclusively of zeros to achieve an exteremely efficient compression rate,
300+
# so that the compressed data also fits in memory.
301+
302+
buffered_stream = io.BytesIO()
303+
n = 20
304+
block_size = 2**n
305+
iterations = 2**(32 - n)
306+
zeros_block = bytes(block_size)
307+
308+
# To avoid writing the whole compressed data, we will write the compressed data
309+
with gzip_ng.open(buffered_stream, "wb") as gz:
310+
for _ in range(iterations):
311+
gz.write(zeros_block)
312+
gz.write(b"\x01" * 123)
313+
buffered_stream.seek(0)
314+
with gzip_ng.open(buffered_stream, "rb") as gz:
315+
for _ in range(iterations):
316+
assert zeros_block == gz.read(block_size)
317+
assert gz.read() == b"\x01" * 123
318+
319+
295320
def test_decompress_incorrect_checksum():
296321
# Create a wrong checksum by using a non-default seed.
297322
wrong_checksum = zlib.crc32(DATA, 50)

0 commit comments

Comments
 (0)