mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
[3.14] gh-133767: Fix use-after-free in the unicode-escape decoder with an error handler (GH-129648) (GH-133942)
If the error handler is used, a new bytes object is created to set as
the object attribute of UnicodeDecodeError, and that bytes object then
replaces the original data. A pointer to the decoded data will became invalid
after destroying that temporary bytes object. So we need other way to return
the first invalid escape from _PyUnicode_DecodeUnicodeEscapeInternal().
_PyBytes_DecodeEscape() does not have such issue, because it does not
use the error handlers registry, but it should be changed for compatibility
with _PyUnicode_DecodeUnicodeEscapeInternal().
(cherry picked from commit 9f69a58623
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
f0a7a6c2cc
commit
69b4387f78
9 changed files with 160 additions and 80 deletions
|
@ -20,8 +20,9 @@ extern PyObject* _PyBytes_FromHex(
|
|||
|
||||
// Helper for PyBytes_DecodeEscape that detects invalid escape chars.
|
||||
// Export for test_peg_generator.
|
||||
PyAPI_FUNC(PyObject*) _PyBytes_DecodeEscape(const char *, Py_ssize_t,
|
||||
const char *, const char **);
|
||||
PyAPI_FUNC(PyObject*) _PyBytes_DecodeEscape2(const char *, Py_ssize_t,
|
||||
const char *,
|
||||
int *, const char **);
|
||||
|
||||
|
||||
// Substring Search.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue