https://github.com/python/cpython/commit/8fc66aef6d7b3ae58f43f5c66f9366cc8cbbfcd2
commit: 8fc66aef6d7b3ae58f43f5c66f9366cc8cbbfcd2
branch: main
author: Stan Ulbrych <[email protected]>
committer: gpshead <[email protected]>
date: 2026-04-12T18:14:54-07:00
summary:

gh-148395: Fix a possible UAF in `{LZMA,BZ2,_Zlib}Decompressor` (GH-148396)

Fix dangling input pointer after `MemoryError` in 
_lzma/_bz2/_ZlibDecompressor.decompress

files:
A Misc/NEWS.d/next/Security/2026-04-10-16-28-21.gh-issue-148395.kfzm0G.rst
M Modules/_bz2module.c
M Modules/_lzmamodule.c
M 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
index 00000000000000..9502189ab199c1
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2026-04-10-16-28-21.gh-issue-148395.kfzm0G.rst
@@ -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.
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
index d6c5c39ff9102a..4bff90e6fd2b2e 100644
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -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;
 }
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
index 3c391675d7b93e..00ee68dcea2d0d 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -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;
 }
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index f67434ecdc908c..9c5820fbe97a6b 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -1669,6 +1669,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
     return result;
 
 error:
+    self->zst.next_in = NULL;
     Py_XDECREF(result);
     return NULL;
 }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to