# 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.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 1 Apr 2025
- **Also known as:** RUSTSEC-2025-0020

## 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 | Ecosystem | 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.

## 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.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-pph8-gcv7-4qj5 and fix it if it is affected.

What it is: GHSA-pph8-gcv7-4qj5 is a memory corruption vulnerability in pyo3, published on 1 Apr 2025. 
Exploitation: There is no known exploitation of GHSA-pph8-gcv7-4qj5 in the wild and no public exploit code.

Affected packages and fixed versions:
- pyo3 (crates.io): affected from 0.0.0-0; fixed in 0.24.1
- pyo3 (crates.io): affected from 0.1.0; fixed in 0.24.1
- pyo3 (crates.io): affected from 0.1.0; fixed in 0.24.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-pph8-gcv7-4qj5/ (Markdown: https://insights.sbomify.com/GHSA-pph8-gcv7-4qj5/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-pph8-gcv7-4qj5

---
From sbomify Insights: https://insights.sbomify.com/GHSA-pph8-gcv7-4qj5/
Summaries are generated and may contain mistakes; the official description above is the record.
