[Python-checkins] [3.7] bpo-35214: Fix OOB memory access in unicode escape parser (GH-10506) (GH-10522)

Miss Islington (bot) webhook-mailer at python.org
Tue Nov 13 19:39:41 EST 2018


https://github.com/python/cpython/commit/9fbcb1402efab4e287f25145a69ba14c9c6dbce9
commit: 9fbcb1402efab4e287f25145a69ba14c9c6dbce9
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-11-13T16:39:36-08:00
summary:

[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 746b2d35ea47005054ed774fecaed64fab803d7d)


Co-authored-by: Gregory P. Smith <greg at krypto.org>


https://bugs.python.org/issue35214

files:
A Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.rst
M Objects/unicodeobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.rst b/Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.rst
new file mode 100644
index 000000000000..d462c97d8040
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-11-13-00-40-35.bpo-35214.OQBjph.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 ``'\N'``.  It would read
+one byte beyond the end of the memory allocation.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index fe833a76eadb..71eb654095a6 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6042,7 +6042,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
             }
 
             message = "malformed \\N character escape";
-            if (*s == '{') {
+            if (s < end && *s == '{') {
                 const char *start = ++s;
                 size_t namelen;
                 /* look for the closing brace */



More information about the Python-checkins mailing list