]> granicus.if.org Git - python/commitdiff
bpo-31825: Fixed OverflowError in the 'unicode-escape' codec (GH-4058) (#4059)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 20 Oct 2017 14:41:29 +0000 (07:41 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 20 Oct 2017 14:41:29 +0000 (17:41 +0300)
and in codecs.escape_decode() when decode an escaped non-ascii byte.
(cherry picked from commit 56cb465cc93dcb35aaf7266ca3dbe2dcff1fac5f)

Lib/test/test_codecs.py
Misc/NEWS.d/next/Core and Builtins/2017-10-20-14-07-46.bpo-31825.gJvmGW.rst [new file with mode: 0644]
Objects/bytesobject.c
Objects/unicodeobject.c
Python/ast.c

index 1e63ed8d79381b1f8d3f6ac097640e8845461c34..de6868a46c47467afc8cab86d520b7556166283e 100644 (file)
@@ -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 (file)
index 0000000..18e81af
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed OverflowError in the 'unicode-escape' codec and in
+codecs.escape_decode() when decode an escaped non-ascii byte.
index 4c55294d9d8c8a1e6c56396f760bcaf84b5dca13..489062e83559bf0db5f676451991683c2eb30b0a 100644 (file)
@@ -1255,7 +1255,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;
         }
index e9fc6580383dde518807a30f3e342850e633bd36..64905e84b149c9d1c393afa99c8a049d960d14bf 100644 (file)
@@ -6174,7 +6174,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;
         }
index 2973b9fd86692fd179ca6d1118fc99fb39208c0a..d2710259acb723959906bdb03e9354b1e5f93158 100644 (file)
@@ -4127,7 +4127,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);