]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-148395: Fix a possible UAF in `{LZMA,BZ2,_Zlib}Decompressor` (GH-148396)
authorStan Ulbrych <stan@python.org>
Mon, 13 Apr 2026 01:14:54 +0000 (02:14 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2026 01:14:54 +0000 (18:14 -0700)
Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress

Misc/NEWS.d/next/Security/2026-04-10-16-28-21.gh-issue-148395.kfzm0G.rst [new file with mode: 0644]
Modules/_bz2module.c
Modules/_lzmamodule.c
Modules/zlibmodule.c

diff --git a/Misc/NEWS.d/next/Security/2026-04-10-16-28-21.gh-issue-148395.kfzm0G.rst b/Misc/NEWS.d/next/Security/2026-04-10-16-28-21.gh-issue-148395.kfzm0G.rst
new file mode 100644 (file)
index 0000000..9502189
--- /dev/null
@@ -0,0 +1,5 @@
+Fix a dangling input pointer in :class:`lzma.LZMADecompressor`,
+:class:`bz2.BZ2Decompressor`, and internal :class:`!zlib._ZlibDecompressor`
+when memory allocation fails with :exc:`MemoryError`, which could let a
+subsequent :meth:`!decompress` call read or write through a stale pointer to
+the already-released caller buffer.
index d6c5c39ff9102ab28312b20dda71cfc9805f5e6c..4bff90e6fd2b2e0a19148fb94027e7fc6ae234d1 100644 (file)
@@ -571,6 +571,7 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
     return result;
 
 error:
+    bzs->next_in = NULL;
     Py_XDECREF(result);
     return NULL;
 }
index 3c391675d7b93e70bae1260a71e51acdf6e7c1a3..00ee68dcea2d0d97beccd86e1a6c13044da97207 100644 (file)
@@ -1100,6 +1100,7 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length)
     return result;
 
 error:
+    lzs->next_in = NULL;
     Py_XDECREF(result);
     return NULL;
 }
index f67434ecdc908c55d3e469dd054971cf8667f3ab..9c5820fbe97a6b04a7c17d72cab770e08e87acb8 100644 (file)
@@ -1669,6 +1669,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
     return result;
 
 error:
+    self->zst.next_in = NULL;
     Py_XDECREF(result);
     return NULL;
 }