Skip to content

Commit b6f4472

Browse files
authored
[2.7] bpo-35214: Fix OOB memory access in unicode escape parser (GH-10506) (GH-10538)
Discovered using clang's MemorySanitizer. A msan build will fail by simply executing: ./python -c 'u"\N"' (cherry picked from commit 746b2d3) Co-authored-by: Gregory P. Smith <[email protected]> [Google LLC]
1 parent 815fa49 commit b6f4472

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed an out of bounds memory access when parsing a truncated unicode escape
2+
sequence at the end of a string such as ``u'\N'``. It would read one byte
3+
beyond the end of the memory allocation.

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
29502950
if (ucnhash_CAPI == NULL)
29512951
goto ucnhashError;
29522952
}
2953-
if (*s == '{') {
2953+
if (s < end && *s == '{') {
29542954
const char *start = s+1;
29552955
/* look for the closing brace */
29562956
while (*s != '}' && s < end)

0 commit comments

Comments
 (0)