diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-11-13-17-20-18.bpo-35214.AH2F87.rst b/Misc/NEWS.d/next/Core and Builtins/2018-11-13-17-20-18.bpo-35214.AH2F87.rst new file mode 100644 index 00000000000000..91f6916ae19195 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-11-13-17-20-18.bpo-35214.AH2F87.rst @@ -0,0 +1,3 @@ +Fixed an out of bounds memory access when parsing a truncated unicode escape +sequence at the end of a string such as ``u'\N'``. It would read one byte +beyond the end of the memory allocation. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b76db619ad7614..21d994cdd6b6f2 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2950,7 +2950,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, if (ucnhash_CAPI == NULL) goto ucnhashError; } - if (*s == '{') { + if (s < end && *s == '{') { const char *start = s+1; /* look for the closing brace */ while (*s != '}' && s < end)