Skip to content

Check memory errors using address sanitizer #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 27, 2023
Merged
1 change: 1 addition & 0 deletions .github/release_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/isal/isal_zlibmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
Expand Down
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down