BIT-python-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.
Affected Software
Event History
Frequently Asked Questions
Which applications are exposed to this issue?
Only CPython code that calls bytes.decode("unicode_escape", error="ignore") or bytes.decode("unicode_escape", error="replace") is affected. Code that does not use the unicode_escape encoding or does not use an error handler is not affected.
What must occur for exploitation?
An attacker would need to cause the application to process bytes through the unicode_escape decoder with the ignore or replace error handler. The reported vector is local and has high attack complexity.
What can be done if an update cannot be applied immediately?
Avoid using the error= handler with bytes.decode("unicode_escape"). Instead, call decode without that handler and catch DecodeError with try-except.