GHSA-pph8-gcv7-4qj5 Risk of buffer overflow in `PyString::from_object`
Attackers can trigger a buffer overflow in PyString::from_object to leak memory contents via Python exceptions, affecting Rust applications using PyO3.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Not stated
- Victim action needed
- Not needed
- Fix
- Available
What is GHSA-pph8-gcv7-4qj5?
GHSA-pph8-gcv7-4qj5 is a memory corruption vulnerability in pyo3, published on 1 Apr 2025.
Official description
PyString::from_object took &str arguments and forwarded them directly to the Python C API without checking for terminating nul bytes. This could lead the Python interpreter to read beyond the end of the &str data and potentially leak contents of the out-of-bounds read (by raising a Python exception containing a copy of the data including the overflow).
In PyO3 0.24.1 this function will now allocate a CString to guarantee a terminating nul bytes. PyO3 0.25 will likely offer an alternative API which takes &CStr arguments.
Which versions are affected by GHSA-pph8-gcv7-4qj5?
3 open source packages ship an affected version, including pyo3.
| Package | Affected | Fixed in |
|---|---|---|
pyo3 crates.io | From 0.0.0-0 | 0.24.1 |
pyo3 crates.io | From 0.1.0 | 0.24.1 |
pyo3 crates.io | From 0.1.0 | 0.24.1 |
How do I fix GHSA-pph8-gcv7-4qj5?
Upgrade pyo3 to 0.24.1 or later.
Upgrade to the fixed version. Memory-safe languages, compiler hardening and fuzzing prevent most new cases. More about Memory corruption.
Is GHSA-pph8-gcv7-4qj5 being exploited?
There is no known exploitation of GHSA-pph8-gcv7-4qj5 in the wild and no public exploit code.
Sources
Also known as RUSTSEC-2025-0020.