From ba99bf98f0f1e775efb6fb52bad3bde971582834 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 10:52:46 +0100 Subject: [PATCH 01/15] Update included zlib-ng distribution to 2.3.3. --- CHANGELOG.rst | 1 + src/zlib_ng/zlib-ng | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8a481e4..e30b5ea 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Changelog version 1.0.1-dev ----------------- ++ Update included zlib-ng distribution to 2.3.3. + Fix ``gzip_ng_threaded`` writers that waited forever when writing to the underlying file failed, for example, because the disk was full. A later call to ``write()``, ``flush()``, or ``close()`` raises the error. After an error, diff --git a/src/zlib_ng/zlib-ng b/src/zlib_ng/zlib-ng index 4254390..1273109 160000 --- a/src/zlib_ng/zlib-ng +++ b/src/zlib_ng/zlib-ng @@ -1 +1 @@ -Subproject commit 425439062b114a0f6cf625022c41d929c7e879f9 +Subproject commit 12731092979c6d07f42da27da673a9f6c7b13586 From cba2a3ec766164b71ecc1d386c10d44629435232 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 11:44:21 +0100 Subject: [PATCH 02/15] Use Cmake always --- .github/workflows/ci.yml | 2 +- setup.py | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abb29d4..2157921 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: with: arch: ${{ matrix.os == 'windows-11-arm' && 'arm64' || 'x64' }} - name: Install build dependencies (MacOS) - run: brew install make + run: brew install cmake if: runner.os == 'macOS' - name: Run tests run: tox diff --git a/setup.py b/setup.py index f58cbf8..6884e85 100644 --- a/setup.py +++ b/setup.py @@ -103,20 +103,12 @@ def build_zlib_ng(): build_env["CFLAGS"] = build_env.get("CFLAGS", "") + " -fPIC" # Add -fPIC flag to allow static compilation run_args = dict(cwd=build_dir, env=build_env) - if sys.platform == "darwin": # Cmake does not work properly - subprocess.run([os.path.join(build_dir, "configure")], **run_args) - make_program = "gmake" if shutil.which("gmake") else "make" - subprocess.run([make_program, "libz-ng.a"], **run_args) - elif sys.platform == "linux": - subprocess.run([os.path.join(build_dir, "configure")], **run_args) - subprocess.run(["make", "libz-ng.a", "-j", str(cpu_count)], **run_args) - else: - subprocess.run(["cmake", build_dir], **run_args) - # Do not create test suite and do not perform tests to shorten build times. - # There is no need when stable releases of zlib-ng are used. - subprocess.run(["cmake", "--build", build_dir, "--config", "Release", - "--target", "zlibstatic", - "-j", str(cpu_count)], **run_args) + subprocess.run(["cmake", build_dir], **run_args) + # Do not create test suite and do not perform tests to shorten build times. + # There is no need when stable releases of zlib-ng are used. + subprocess.run(["cmake", "--build", build_dir, "--config", "Release", + "--target", "zlib-ng-static", + "-j", str(cpu_count)], **run_args) if BUILD_CACHE: BUILD_CACHE_FILE.write_text(build_dir) return build_dir From 2f87f7fed57313b93b37612dd5028ef4bf2ddc92 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 11:46:32 +0100 Subject: [PATCH 03/15] Build macos with make --- .github/workflows/ci.yml | 2 +- setup.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2157921..abb29d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: with: arch: ${{ matrix.os == 'windows-11-arm' && 'arm64' || 'x64' }} - name: Install build dependencies (MacOS) - run: brew install cmake + run: brew install make if: runner.os == 'macOS' - name: Run tests run: tox diff --git a/setup.py b/setup.py index 6884e85..6d9f267 100644 --- a/setup.py +++ b/setup.py @@ -103,12 +103,17 @@ def build_zlib_ng(): build_env["CFLAGS"] = build_env.get("CFLAGS", "") + " -fPIC" # Add -fPIC flag to allow static compilation run_args = dict(cwd=build_dir, env=build_env) - subprocess.run(["cmake", build_dir], **run_args) - # Do not create test suite and do not perform tests to shorten build times. - # There is no need when stable releases of zlib-ng are used. - subprocess.run(["cmake", "--build", build_dir, "--config", "Release", - "--target", "zlib-ng-static", - "-j", str(cpu_count)], **run_args) + if sys.platform == "darwin": # Cmake does not work properly + subprocess.run([os.path.join(build_dir, "configure")], **run_args) + make_program = "gmake" if shutil.which("gmake") else "make" + subprocess.run([make_program, "libz-ng.a"], **run_args) + else: + subprocess.run(["cmake", build_dir], **run_args) + # Do not create test suite and do not perform tests to shorten build times. + # There is no need when stable releases of zlib-ng are used. + subprocess.run(["cmake", "--build", build_dir, "--config", "Release", + "--target", "zlib-ng-static", + "-j", str(cpu_count)], **run_args) if BUILD_CACHE: BUILD_CACHE_FILE.write_text(build_dir) return build_dir From acbc3a55583039e415388e5664d9e96c368345f1 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 12:01:47 +0100 Subject: [PATCH 04/15] Publish to PyPI according to PyPA recommended method --- .github/workflows/ci.yml | 66 +++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abb29d4..6ce4b05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,7 +156,31 @@ jobs: env: PYTHON_ZLIB_NG_LINK_DYNAMIC: True - deploy: + make_sdist: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + needs: + - lint + - package-checks + - test-static + - test-dynamic + - test-arch + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 # Optional, use if you use setuptools_scm + submodules: true # Optional, use if you have submodules + persist-credentials: false # Highly recommended as a good security practice to not store credentials in disk, unless you need this for your specific use case + + - name: Build SDist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + build_wheels: if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') runs-on: ${{ matrix.os }} needs: @@ -239,19 +263,33 @@ jobs: python -m build --sdist - uses: actions/upload-artifact@v7 with: - name: "dist-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cibw_archs_linux }}" + name: "cibw-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cibw_archs_linux }}" path: "dist/" - - name: Publish package to TestPyPI - # pypa/gh-action-pypi-publish@master does not work on OSX + + upload_to_pypi: + needs: [ build_wheels, make_sdist ] + environment: pypi + permissions: + id-token: write + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + steps: + - uses: actions/download-artifact@v5 + with: + pattern: cibw-* + path: dist + merge-multiple: true + + - name: Publish to test PyPI # Alpha, Beta and dev releases contain a - in the tag. - if: contains(github.ref, '-') && startsWith(github.ref, 'refs/tags') - run: twine upload --skip-existing -r testpypi dist/* - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} - - name: Publish package to PyPI + if: "contains(github.ref, '-') && startsWith(github.ref, 'refs/tags')" + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true + + - name: Publish to PyPI if: "!contains(github.ref, '-') && startsWith(github.ref, 'refs/tags')" - run: twine upload --skip-existing dist/* - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true From c1ca45cff61d2d87d917bccf9f5b791d14c8f56b Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 12:03:11 +0100 Subject: [PATCH 05/15] Add sanitizer testing --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ce4b05..275fc72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,6 +156,49 @@ jobs: env: PYTHON_ZLIB_NG_LINK_DYNAMIC: True + # Run the tests on CPython builds with AddressSanitizer and ThreadSanitizer + # from https://github.com/nascheme/cpython_sanity. + test-sanitizers: + runs-on: ubuntu-latest + # A crash under ThreadSanitizer can hang instead of exiting. + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + include: + - sanitizer: address + image: ghcr.io/nascheme/cpython-asan:3.14 + # The free-threaded build runs Python threads in parallel. + - sanitizer: thread + image: ghcr.io/nascheme/cpython-tsan:3.14t + container: + image: ${{ matrix.image }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install build dependencies + run: apt-get update && apt-get install -y nasm + - name: Install python-isal with ${{ matrix.sanitizer }} sanitizer + # setuptools-scm needs git, and the container user does not own the + # repository. + run: | + git config --global --add safe.directory "$GITHUB_WORKSPACE" + python -m pip install . pytest pytest-timeout + env: + # The extension modules get -fsanitize from CPython. CFLAGS adds it + # to the C code of ISA-L. + CFLAGS: -fsanitize=${{ matrix.sanitizer }} -fno-omit-frame-pointer -g + - name: Run tests + # Do not set PYTHONDEVMODE. Its debug allocator pads each allocation, + # so AddressSanitizer misses small overflows. --capture=sys prints + # sanitizer reports from C code even when they end the process, and + # -v prints the name of the test before its report. + run: python -m pytest -v tests --capture=sys + env: + # Exit at the first data race. A crash after a race can hang. + TSAN_OPTIONS: halt_on_error=1 + make_sdist: if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') needs: @@ -164,6 +207,7 @@ jobs: - test-static - test-dynamic - test-arch + - test-sanitizers runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 @@ -189,6 +233,7 @@ jobs: - test-static - test-dynamic - test-arch + - test-sanitizers strategy: matrix: os: From 1e9f1626dc5c7a393e891999d07b19abda9dc2b4 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 12:53:09 +0100 Subject: [PATCH 06/15] Ensure cmake is installed on sanitizer --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 275fc72..ec279fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -178,7 +178,7 @@ jobs: with: submodules: recursive - name: Install build dependencies - run: apt-get update && apt-get install -y nasm + run: apt-get update && apt-get install -y cmake - name: Install python-isal with ${{ matrix.sanitizer }} sanitizer # setuptools-scm needs git, and the container user does not own the # repository. From 674f35e3d236b352ebb45c8b8446474240e033dc Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 13:08:03 +0100 Subject: [PATCH 07/15] Fix broken pipe error when piping into programs using the CLI. --- CHANGELOG.rst | 2 ++ src/zlib_ng/gzip_ng.py | 3 +++ tests/test_gzip_ng.py | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e30b5ea..0bf5722 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,8 @@ Changelog version 1.0.1-dev ----------------- + Update included zlib-ng distribution to 2.3.3. ++ Fix BrokenPipeError when piping ``python -m isal.igzip`` into ``head``, + ``less`` or similar programs. + Fix ``gzip_ng_threaded`` writers that waited forever when writing to the underlying file failed, for example, because the disk was full. A later call to ``write()``, ``flush()``, or ``close()`` raises the error. After an error, diff --git a/src/zlib_ng/gzip_ng.py b/src/zlib_ng/gzip_ng.py index f24bdbe..c2afec2 100644 --- a/src/zlib_ng/gzip_ng.py +++ b/src/zlib_ng/gzip_ng.py @@ -304,6 +304,9 @@ def main(): READ_BUFFER_SIZE = args.buffer_size try: shutil.copyfileobj(in_file, out_file, args.buffer_size) + except BrokenPipeError: + # Do not throw errors when a pipe to head or less closes. + pass finally: if in_file is not sys.stdin.buffer: in_file.close() diff --git a/tests/test_gzip_ng.py b/tests/test_gzip_ng.py index 171bd84..41eb954 100644 --- a/tests/test_gzip_ng.py +++ b/tests/test_gzip_ng.py @@ -15,6 +15,7 @@ import re import shutil import struct +import subprocess import sys import tempfile import zlib @@ -496,3 +497,14 @@ def test_adverserial_header(): gzip_file.read() finally: os.remove(tmpfile.name) + + +@pytest.mark.skipif(sys.platform != "linux", reason="bash required") +def test_no_broken_pipe(): + subprocess.run( + [ + "bash", "-c", "-e", "-o", "pipefail", + f"{sys.executable} -m zlib_ng.gzip_ng -cd {TEST_FILE} | head -n 10" + ], + check=True + ) From c55f942ae536b08be9a3a08bbbd82ceeb5b1029f Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 16:19:33 +0100 Subject: [PATCH 08/15] Add cmake to readthedocs.yml --- .readthedocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index cb71cd8..1a83c66 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,6 +14,8 @@ build: os: "ubuntu-22.04" tools: python: "3" + apt_packages: + - cmake # Make sure zlib-ng is cloned alongside submodules: From a2d21760e45d1f5079a8bdb7436297a79a997ae5 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 16:24:10 +0100 Subject: [PATCH 09/15] Set version to 1.1.0 --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0bf5722..11ec8d1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,7 +7,7 @@ Changelog .. This document is user facing. Please word the changes in such a way .. that users understand how the changes affect the new version. -version 1.0.1-dev +version 1.1.0 ----------------- + Update included zlib-ng distribution to 2.3.3. + Fix BrokenPipeError when piping ``python -m isal.igzip`` into ``head``, From a21f7f27ce724765946311bdd35756fb4f7cb00d Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 16:45:07 +0100 Subject: [PATCH 10/15] Fix asan environment --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index dfefd90..1eb5fe9 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,8 @@ commands = coverage xml -i [testenv:asan] +# Use debug python as default python gives address sanitization errors. +basepython=python3d setenv= PYTHONDEVMODE=1 PYTHONUNBUFFERED=1 From 3834e9ab15c1da0df59fa2cb74d3340e26c2a9f2 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 19:38:58 +0100 Subject: [PATCH 11/15] Add extra pypy version, remove redundant sdist build --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec279fb..b6edc07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: - "3.15" - "3.15t" - "pypy-3.11" - - "pypy-3.11" + - "pypy-3.12" os: ["ubuntu-latest"] include: - os: "macos-latest" # For m1 macos @@ -302,10 +302,6 @@ jobs: PYTHON_ZLIB_NG_BUILD_CACHE=True PYTHON_ZLIB_NG_BUILD_CACHE_FILE=${{ runner.temp }}/build_cache CFLAGS="-O3 -DNDEBUG" - - name: Build sdist - if: ${{runner.os == 'Linux' && matrix.cibw_archs_linux == 'x86_64'}} - run: - python -m build --sdist - uses: actions/upload-artifact@v7 with: name: "cibw-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cibw_archs_linux }}" From dade485dce233c1d06623f84133e2e01032fe6fb Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 19:43:16 +0100 Subject: [PATCH 12/15] Support newer python versions --- CHANGELOG.rst | 2 ++ pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0bf5722..94f1052 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,8 @@ Changelog version 1.0.1-dev ----------------- ++ Python 3.10 and PyPy 3.10 are no longer supported. Added support for PyPy + 3.12 and Python 3.15. + Update included zlib-ng distribution to 2.3.3. + Fix BrokenPipeError when piping ``python -m isal.igzip`` into ``head``, ``less`` or similar programs. diff --git a/pyproject.toml b/pyproject.toml index 531017a..65409e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,11 +15,11 @@ requires-python = ">=3.9" # Because of setuptools version classifiers = [ "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: C", From 459fa5c06d1cb6961ee96e643986c81283ffc21a Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 16:45:07 +0100 Subject: [PATCH 13/15] Fix asan environment --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index dfefd90..1eb5fe9 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,8 @@ commands = coverage xml -i [testenv:asan] +# Use debug python as default python gives address sanitization errors. +basepython=python3d setenv= PYTHONDEVMODE=1 PYTHONUNBUFFERED=1 From d3ad519a4afbf9c594b3bbeaae9794771d510652 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Tue, 3 Nov 2026 19:52:11 +0100 Subject: [PATCH 14/15] Prevent the empty string object from being resized --- src/zlib_ng/zlib_ngmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/zlib_ng/zlib_ngmodule.c b/src/zlib_ng/zlib_ngmodule.c index 59233e5..d2b5e79 100644 --- a/src/zlib_ng/zlib_ngmodule.c +++ b/src/zlib_ng/zlib_ngmodule.c @@ -1183,8 +1183,10 @@ decompress_buf(ZlibDecompressor *self, Py_ssize_t max_length) self->avail_in_real += self->zst.avail_in; - if (_PyBytes_Resize(&return_value, self->zst.next_out - - (uint8_t *)PyBytes_AS_STRING(return_value)) != 0) { + /* Prevent empty string object from being resized. */ + if (PyBytes_GET_SIZE(return_value) != 0 && + _PyBytes_Resize(&return_value, self->zst.next_out - + (uint8_t *)PyBytes_AS_STRING(return_value)) != 0) { goto error; } From 39cec01898a4a44ac988a40e98fd8d8cbbcaacd9 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Wed, 4 Nov 2026 14:07:07 +0100 Subject: [PATCH 15/15] Fix copy paste error. --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4e1eee8..5aabc60 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,7 +12,7 @@ version 1.1.0 + Python 3.10 and PyPy 3.10 are no longer supported. Added support for PyPy 3.12 and Python 3.15. + Update included zlib-ng distribution to 2.3.3. -+ Fix BrokenPipeError when piping ``python -m isal.igzip`` into ``head``, ++ Fix BrokenPipeError when piping ``python -m zlib_ng.gzip_ng`` into ``head``, ``less`` or similar programs. + Fix ``gzip_ng_threaded`` writers that waited forever when writing to the underlying file failed, for example, because the disk was full. A later call