]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-148395: Fix a possible UAF in `{LZMA,BZ2,_Zlib}Decompressor` (GH-148396...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 13 Apr 2026 01:35:24 +0000 (03:35 +0200)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2026 01:35:24 +0000 (01:35 +0000)
gh-148395: Fix a possible UAF in `{LZMA,BZ2,_Zlib}Decompressor` (GH-148396)

Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress
(cherry picked from commit 8fc66aef6d7b3ae58f43f5c66f9366cc8cbbfcd2)

Co-authored-by: Stan Ulbrych <stan@python.org>
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 661847ad26702ee550421236de940ceac55f1a8f..6c83ad3fa33d3d56b766eef97cbfc88d96a07024 100644 (file)
@@ -589,6 +589,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 97f3a8f03da9a86c776655a3f9364cdc756c17cd..8d22ad318dabd1542323347e2063f7b71c778fa6 100644 (file)
@@ -1112,6 +1112,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 f59f9a76abd5ea269e384b3e14db0550b2fe3cff..2b7def45cae476e926c7aaa3cda7b9e0c82b01a8 100644 (file)
@@ -1675,6 +1675,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
     return result;
 
 error:
+    self->zst.next_in = NULL;
     Py_XDECREF(result);
     return NULL;
 }