[3.14] gh-148395: Fix a possible UAF in {LZMA,BZ2,_Zlib}Decompressor (GH-148396) (#148480)

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 8fc66aef6d)

Co-authored-by: Stan Ulbrych <stan@python.org>
This commit is contained in:
Miss Islington (bot)
2026-04-13 03:40:54 +02:00
committed by GitHub
parent 48c3c7fb73
commit 6a5f79c8d7
4 changed files with 8 additions and 0 deletions
@@ -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.
+1
View File
@@ -593,6 +593,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;
}
+1
View File
@@ -1120,6 +1120,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;
}
+1
View File
@@ -1675,6 +1675,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
return result;
error:
self->zst.next_in = NULL;
Py_XDECREF(result);
return NULL;
}