From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 12 Jun 2019 11:50:11 +0000 (-0700) Subject: bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859) X-Git-Tag: v3.7.4rc1~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d561f848b235f2011a43b705d112055b92fa2366;p=thirdparty%2FPython%2Fcpython.git bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859) Escape ``\r``, ``\0`` and ``\x1a`` (end-of-file on Windows) in Unicode strings. (cherry picked from commit 38ab7d4721b422547f7b46b9d68968863fa70573) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/pickle.py b/Lib/pickle.py index e6d003787bad..bfa3c0361b73 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -749,7 +749,10 @@ class _Pickler: self.write(BINUNICODE + pack("= 256 || ch == '\\' || ch == '\n') { + else if (ch >= 256 || + ch == '\\' || ch == 0 || ch == '\n' || ch == '\r' || + ch == 0x1a) + { /* -1: subtract 1 preallocated byte */ p = _PyBytesWriter_Prepare(&writer, p, 6-1); if (p == NULL)