]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-148395: Fix a possible UAF in `{LZMA,BZ2}Decompressor` (GH-148396) (#148504) 3.11 98846/head
authorStan Ulbrych <stan@python.org>
Mon, 13 Apr 2026 21:42:36 +0000 (22:42 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2026 21:42:36 +0000 (22:42 +0100)
Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress

(cherry picked from commit 8fc66aef6d7b3ae58f43f5c66f9366cc8cbbfcd2)

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

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..349d1cf
--- /dev/null
@@ -0,0 +1,5 @@
+Fix a dangling input pointer in :class:`lzma.LZMADecompressor`,
+and :class:`bz2.BZ2Decompressor`
+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 798e9efc628f0567e913223232319efad6b5f7f5..b08ac5e44e52f4d75e291a1d2d0b40e08e4a62ee 100644 (file)
@@ -595,6 +595,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 97453a280881313e397002ac6a06e5710110ddca..51106a6a075b3015f06c91cf189440a0aab412b1 100644 (file)
@@ -1105,6 +1105,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;
 }