CVE-2025-4516: Use-after-free in "unicode_escape" decoder with error handler
There is an issue in CPython when using bytes.decode("unicodeescape", error="ignore|replace"). If you are not using the "unicodeescape" 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.
Other sources
Use-after-free in "unicodeescape" decoder with error handler
— Microsoft
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 3.9.19-14 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 3.12.9-2 - Upgrade
Upgrade
ubuntu/python3.6to a version that resolves this vulnerability.Fixed in 3.6.9-1~18.04ubuntu1.13+esm5 - Upgrade
Upgrade
ubuntu/python3.7to a version that resolves this vulnerability.Fixed in 3.7.5-2ubuntu1~18.04.2+esm6 - Upgrade
Upgrade
ubuntu/python3.8to a version that resolves this vulnerability.Fixed in 3.8.0-3ubuntu1~18.04.2+esm5 - Upgrade
Upgrade
ubuntu/python3.8to a version that resolves this vulnerability.Fixed in 3.8.10-0ubuntu1~20.04.18+esm1 - Upgrade
Upgrade
ubuntu/python3.9to a version that resolves this vulnerability.Fixed in 3.9.5-3ubuntu0~20.04.1+esm5 - Upgrade
Upgrade
ubuntu/python3.10to a version that resolves this vulnerability.Fixed in 3.10.12-1~22.04.10 - Upgrade
Upgrade
ubuntu/python3.11to a version that resolves this vulnerability.Fixed in 3.11.0~rc1-1~22.04.1~esm4 - Upgrade
Upgrade
ubuntu/python3.12to a version that resolves this vulnerability.Fixed in 3.12.3-1ubuntu0.6 - Upgrade
Upgrade
ubuntu/python3.14to a version that resolves this vulnerability.Fixed in 3.14.0-1 - Upgrade
Upgrade
debian/python3.11to a version that resolves this vulnerability.Fixed in 3.11.2-6+deb12u7 - Upgrade
Upgrade
debian/python3.13to a version that resolves this vulnerability.Fixed in 3.13.3-4 - Upgrade
Upgrade
debian/python3.9to a version that resolves this vulnerability.Fixed in 3.9.2-1+deb11u4 - Upgrade
Upgrade
alpine/python3to a version that resolves this vulnerability.Fixed in 3.11.12-r1 - Upgrade
Upgrade
alpine/python3to a version that resolves this vulnerability.Fixed in 3.12.10-r1
Event History
Frequently Asked Questions
What is the severity of CVE-2025-4516?
CVE-2025-4516 is considered a medium severity vulnerability as it affects the handling of byte decoding in CPython.
How do I fix CVE-2025-4516?
To mitigate CVE-2025-4516, avoid using the 'unicode_escape' encoding with an error handler by wrapping the bytes in a try-except block instead.
Who is affected by CVE-2025-4516?
Users of CPython who utilize the 'bytes.decode' method with 'unicode_escape' encoding and specific error handlers are directly affected by CVE-2025-4516.
What versions of CPython are impacted by CVE-2025-4516?
CVE-2025-4516 affects all active versions of CPython that utilize the 'bytes.decode' method incorrectly with 'unicode_escape' encoding.
Is there a workaround for CVE-2025-4516?
Yes, a workaround for CVE-2025-4516 involves avoiding the use of the error handler in the 'bytes.decode' method.