diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-20 17:08:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-20 17:08:15 +0300 |
commit | 56cb465cc93dcb35aaf7266ca3dbe2dcff1fac5f (patch) | |
tree | b9bce18e156f23827247be42659d6fe99cd5c1cd | |
parent | 525f40d231aba2c004619fc7a5207171ed65b0cb (diff) | |
download | cpython-git-56cb465cc93dcb35aaf7266ca3dbe2dcff1fac5f.tar.gz |
bpo-31825: Fixed OverflowError in the 'unicode-escape' codec (#4058)
and in codecs.escape_decode() when decode an escaped non-ascii byte.
-rw-r--r-- | Lib/test/test_codecs.py | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2017-10-20-14-07-46.bpo-31825.gJvmGW.rst | 2 | ||||
-rw-r--r-- | Objects/bytesobject.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 2 | ||||
-rw-r--r-- | Python/ast.c | 2 |
5 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 1e63ed8d79..de6868a46c 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1203,6 +1203,8 @@ class EscapeDecodeTest(unittest.TestCase): check(br"\8", b"\\8") with self.assertWarns(DeprecationWarning): check(br"\9", b"\\9") + with self.assertWarns(DeprecationWarning): + check(b"\\\xfa", b"\\\xfa") def test_errors(self): decode = codecs.escape_decode @@ -2474,6 +2476,8 @@ class UnicodeEscapeTest(unittest.TestCase): check(br"\8", "\\8") with self.assertWarns(DeprecationWarning): check(br"\9", "\\9") + with self.assertWarns(DeprecationWarning): + check(b"\\\xfa", "\\\xfa") def test_decode_errors(self): decode = codecs.unicode_escape_decode diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-10-20-14-07-46.bpo-31825.gJvmGW.rst b/Misc/NEWS.d/next/Core and Builtins/2017-10-20-14-07-46.bpo-31825.gJvmGW.rst new file mode 100644 index 0000000000..18e81afa1f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-10-20-14-07-46.bpo-31825.gJvmGW.rst @@ -0,0 +1,2 @@ +Fixed OverflowError in the 'unicode-escape' codec and in +codecs.escape_decode() when decode an escaped non-ascii byte. diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 6a4eb67808..48b6501f7a 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -1257,7 +1257,7 @@ PyObject *PyBytes_DecodeEscape(const char *s, if (first_invalid_escape != NULL) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "invalid escape sequence '\\%c'", - *first_invalid_escape) < 0) { + (unsigned char)*first_invalid_escape) < 0) { Py_DECREF(result); return NULL; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index bb1c0830fc..2f308774d7 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6136,7 +6136,7 @@ PyUnicode_DecodeUnicodeEscape(const char *s, if (first_invalid_escape != NULL) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "invalid escape sequence '\\%c'", - *first_invalid_escape) < 0) { + (unsigned char)*first_invalid_escape) < 0) { Py_DECREF(result); return NULL; } diff --git a/Python/ast.c b/Python/ast.c index 6989965efa..a6cc0f7e04 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4147,7 +4147,7 @@ decode_utf8(struct compiling *c, const char **sPtr, const char *end) static int warn_invalid_escape_sequence(struct compiling *c, const node *n, - char first_invalid_escape_char) + unsigned char first_invalid_escape_char) { PyObject *msg = PyUnicode_FromFormat("invalid escape sequence \\%c", first_invalid_escape_char); |