Skip to content

Commit fdc485a

Browse files
bpo-35214: Fix OOB memory access in unicode escape parser (GH-10506)
Discovered using clang's MemorySanitizer when it ran python3's test_fstring test_misformed_unicode_character_name. An msan build will fail by simply executing: ./python -c 'u"\N"' (cherry picked from commit 746b2d3) Co-authored-by: Gregory P. Smith <[email protected]>
1 parent ae88781 commit fdc485a

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
2+
escape sequence at the end of a string such as ``'\N'``. It would read
3+
one byte beyond the end of the memory allocation.

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6133,7 +6133,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
61336133
}
61346134

61356135
message = "malformed \\N character escape";
6136-
if (*s == '{') {
6136+
if (s < end && *s == '{') {
61376137
const char *start = ++s;
61386138
size_t namelen;
61396139
/* look for the closing brace */

0 commit comments

Comments
 (0)