diff --git a/.github/release_checklist.md b/.github/release_checklist.md index c47123ba..7093fe46 100644 --- a/.github/release_checklist.md +++ b/.github/release_checklist.md @@ -5,6 +5,7 @@ Release checklist - [ ] Set version to a stable number. - [ ] Change current development version in `CHANGELOG.rst` to stable version. - [ ] Change the version in `__init__.py` +- [ ] Check if the address sanitizer does not find any problems using `tox -e asan` - [ ] Merge the release branch into `main`. - [ ] Created an annotated tag with the stable version number. Include changes from CHANGELOG.rst. diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0f1eaff3..d51e515b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,13 @@ 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.6.0-dev +----------------- ++ Fix a memory leak that occurred when an error was thrown for a gzip header + with the wrong magic numbers. ++ Fix a memory leak that occurred when isal_zlib.decompressobj was given a + wrong wbits value. + version 1.5.1 ----------------- + Fix a memory leak in the GzipReader.readall implementation. diff --git a/src/isal/isal_zlibmodule.c b/src/isal/isal_zlibmodule.c index 257260f8..2c5c8a92 100644 --- a/src/isal/isal_zlibmodule.c +++ b/src/isal/isal_zlibmodule.c @@ -793,6 +793,7 @@ isal_zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict) err = wbits_to_flag_and_hist_bits_inflate(wbits, &hist_bits, &flag); if (err < 0) { PyErr_Format(PyExc_ValueError, "Invalid wbits value: %d", wbits); + Py_DECREF(self); return NULL; } else if (err == 0) { @@ -1683,9 +1684,11 @@ GzipReader_read_into_buffer(GzipReader *self, uint8_t *out_buffer, size_t out_bu if (!(magic1 == 0x1f && magic2 == 0x8b)) { Py_BLOCK_THREADS; + PyObject *magic_obj = PyBytes_FromStringAndSize((char *)current_pos, 2); PyErr_Format(BadGzipFile, "Not a gzipped file (%R)", - PyBytes_FromStringAndSize((char *)current_pos, 2)); + magic_obj); + Py_DECREF(magic_obj); return -1; }; uint8_t method = current_pos[2]; diff --git a/tox.ini b/tox.ini index c94c6690..256ee95e 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,15 @@ commands = coverage html -i coverage xml -i +[testenv:asan] +setenv= + PYTHONDEVMODE=1 + PYTHONMALLOC=malloc + CFLAGS=-lasan -fsanitize=address -fno-omit-frame-pointer +allowlist_externals=bash +commands= + bash -c 'export LD_PRELOAD=$(gcc -print-file-name=libasan.so) && printenv LD_PRELOAD && python -c "from isal import isal_zlib" && pytest tests' + [testenv:compliance] deps=pytest commands=