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.
Details
| Severity | Base Score | CVE |
|---|---|---|
| MEDIUM | 5.9 | CVE-2025-4516 |
Exploitation
To exploit this vulnerability, an attacker must have local access to the system and can trigger the issue by using the `bytes.decode()` method with the `unicode_escape` encoding and an error handler set to either ‘ignore’ or ‘replace’. This could lead to unexpected behavior in the application if not properly handled.
Affected Products
- CPython: The core implementation of the Python programming language, which is affected when using specific decoding methods.
Mitigation
To mitigate this issue, users should avoid using the `error=` handler with `bytes.decode()` when using the `unicode_escape` encoding. Instead, wrap the call in a try-except block to catch any potential DecodeError.
