# CVE-2025-4516: Use-after-free in "unicode_escape" decoder with error handler

> A use-after-free vulnerability in CPython's unicode_escape decoder allows attackers to cause crashes or execute code when specific error handlers are used.

- **Severity:** Medium 5.9 (`CVSS:4.0/AV:L/AC:H/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 15 May 2025
- **Updated:** 31 Jul 2026
- **Also known as:** ALPINE-CVE-2025-4516, AZL-61865, AZL-61870, BELL-CVE-2025-4516, BIT-libpython-2025-4516, BIT-python-2025-4516, BIT-python-min-2025-4516, CLEANSTART-2026-PS24751, CLSA-2025-1753209049, CLSA-2026-1767700070, CLSA-2026-1767700458, DEBIAN-CVE-2025-4516, ECHO-0e3f-250a-3e24, GHSA-j8r3-cghj-9jhg, MINI-gmw5-575m-65j7, MINI-hv4q-9j92-qh2c, MINI-pxv3-xjwm-9cxm, MINI-wwmg-3vxc-x25m, OESA-2025-2288, OESA-2025-2289, PSF-2025-4, SUSE-SU-2025:01877-1, SUSE-SU-2025:02038-1, UBUNTU-CVE-2025-4516, openSUSE-SU-2025:15141-1, openSUSE-SU-2025:15154-1, openSUSE-SU-2025:15163-1, openSUSE-SU-2025:15190-1, openSUSE-SU-2025:15191-1, openSUSE-SU-2025:15192-1

## What is CVE-2025-4516?

CVE-2025-4516 is a medium-severity use after free vulnerability in CPython, published on 15 May 2025. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

There is an issue in CPython when using `bytes.decode("unicode_escape", error="ignore|replace")`. If you are not using the "unicode_escape" encoding or an error handler your usage is not affected. To work-around this issue you may stop using the error= handler and instead wrap the bytes.decode() call in a try-except catching the DecodeError.

Weakness: CWE-416 (Use After Free)

## Which versions are affected by CVE-2025-4516?

3 open source packages ship an affected version, including libpython, python and python-min.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `libpython` | Bitnami | All versions | 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.4 |
| `python` | Bitnami | All versions | 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.4 |
| `python-min` | Bitnami | All versions | 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.4 |
| `python3` | SUSE:Linux Enterprise Micro 5.1 | All versions | 3.6.15-150000.3.176.1 |
| `python3` | SUSE:Linux Enterprise Micro 5.1 | All versions | 3.6.15-150000.3.179.1 |
| `python3-core` | SUSE:Linux Enterprise Micro 5.1 | All versions | 3.6.15-150000.3.176.1 |
| `python3-core` | SUSE:Linux Enterprise Micro 5.1 | All versions | 3.6.15-150000.3.179.1 |
| `python310` | openSUSE:Tumbleweed | All versions | 3.10.17-4.1 |
| `python311` | openSUSE:Tumbleweed | All versions | 3.11.12-4.1 |
| `python312` | openSUSE:Tumbleweed | All versions | 3.12.10-4.1 |
| `python313` | openSUSE:Tumbleweed | All versions | 3.13.3-3.1 |
| `python314` | openSUSE:Tumbleweed | All versions | 3.14.0~b1-3.1 |
| `python39` | openSUSE:Tumbleweed | All versions | 3.9.22-3.1 |

## How do I fix CVE-2025-4516?

Upgrade libpython to a fixed version for your release line: 3.9.23, 3.10.18, 3.11.13 or 3.12.11.

## Is CVE-2025-4516 being exploited?

There is no known exploitation of CVE-2025-4516 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-4516 and fix it if it is affected.

What it is: CVE-2025-4516 is a medium-severity use after free vulnerability in CPython, published on 15 May 2025. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2025-4516 in the wild and no public exploit code.

Affected packages and fixed versions:
- libpython (Bitnami): affected all versions; fixed in 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.4
- python (Bitnami): affected all versions; fixed in 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.4
- python-min (Bitnami): affected all versions; fixed in 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.4

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/CVE-2025-4516/ (Markdown: https://insights.sbomify.com/CVE-2025-4516/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2025-4516
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2025-4516
- OSV: https://osv.dev/vulnerability/CVE-2025-4516

---
From sbomify Insights: https://insights.sbomify.com/CVE-2025-4516/
Summaries are generated and may contain mistakes; the official description above is the record.
