Skip to content

Commit 5871c6f

Browse files
authored
Merge pull request #171 from pycompression/asan
Check memory errors using address sanitizer
2 parents 367745a + e677817 commit 5871c6f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

.github/release_checklist.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release checklist
55
- [ ] Set version to a stable number.
66
- [ ] Change current development version in `CHANGELOG.rst` to stable version.
77
- [ ] Change the version in `__init__.py`
8+
- [ ] Check if the address sanitizer does not find any problems using `tox -e asan`
89
- [ ] Merge the release branch into `main`.
910
- [ ] Created an annotated tag with the stable version number. Include changes
1011
from CHANGELOG.rst.

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ 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 1.6.0-dev
11+
-----------------
12+
+ Fix a memory leak that occurred when an error was thrown for a gzip header
13+
with the wrong magic numbers.
14+
+ Fix a memory leak that occurred when isal_zlib.decompressobj was given a
15+
wrong wbits value.
16+
1017
version 1.5.1
1118
-----------------
1219
+ Fix a memory leak in the GzipReader.readall implementation.

src/isal/isal_zlibmodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ isal_zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict)
793793
err = wbits_to_flag_and_hist_bits_inflate(wbits, &hist_bits, &flag);
794794
if (err < 0) {
795795
PyErr_Format(PyExc_ValueError, "Invalid wbits value: %d", wbits);
796+
Py_DECREF(self);
796797
return NULL;
797798
}
798799
else if (err == 0) {
@@ -1683,9 +1684,11 @@ GzipReader_read_into_buffer(GzipReader *self, uint8_t *out_buffer, size_t out_bu
16831684

16841685
if (!(magic1 == 0x1f && magic2 == 0x8b)) {
16851686
Py_BLOCK_THREADS;
1687+
PyObject *magic_obj = PyBytes_FromStringAndSize((char *)current_pos, 2);
16861688
PyErr_Format(BadGzipFile,
16871689
"Not a gzipped file (%R)",
1688-
PyBytes_FromStringAndSize((char *)current_pos, 2));
1690+
magic_obj);
1691+
Py_DECREF(magic_obj);
16891692
return -1;
16901693
};
16911694
uint8_t method = current_pos[2];

tox.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ commands =
2222
coverage html -i
2323
coverage xml -i
2424

25+
[testenv:asan]
26+
setenv=
27+
PYTHONDEVMODE=1
28+
PYTHONMALLOC=malloc
29+
CFLAGS=-lasan -fsanitize=address -fno-omit-frame-pointer
30+
allowlist_externals=bash
31+
commands=
32+
bash -c 'export LD_PRELOAD=$(gcc -print-file-name=libasan.so) && printenv LD_PRELOAD && python -c "from isal import isal_zlib" && pytest tests'
33+
2534
[testenv:compliance]
2635
deps=pytest
2736
commands=

0 commit comments

Comments
 (0)