Skip to content

Commit 9fbcb14

Browse files
[3.7] bpo-35214: Fix OOB memory access in unicode escape parser (GH-10506) (GH-10522)
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]> https://bugs.python.org/issue35214
1 parent c30830b commit 9fbcb14

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
@@ -6042,7 +6042,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
60426042
}
60436043

60446044
message = "malformed \\N character escape";
6045-
if (*s == '{') {
6045+
if (s < end && *s == '{') {
60466046
const char *start = ++s;
60476047
size_t namelen;
60486048
/* look for the closing brace */

0 commit comments

Comments
 (0)