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>
--- /dev/null
+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.
return result;
error:
+ bzs->next_in = NULL;
Py_XDECREF(result);
return NULL;
}
return result;
error:
+ lzs->next_in = NULL;
Py_XDECREF(result);
return NULL;
}
return result;
error:
+ self->zst.next_in = NULL;
Py_XDECREF(result);
return NULL;
}