[Python-checkins] cpython (merge 3.3 -> default): Issue #17710: Fix pickle raising a SystemError on bogus input.
antoine.pitrou
python-checkins at python.org
Mon Apr 15 22:20:08 CEST 2013
http://hg.python.org/cpython/rev/5a16d2992112
changeset: 83401:5a16d2992112
parent: 83396:7f4325dc4256
parent: 83400:4e412cbaaf96
user: Antoine Pitrou <solipsis at pitrou.net>
date: Mon Apr 15 21:55:14 2013 +0200
summary:
Issue #17710: Fix pickle raising a SystemError on bogus input.
files:
Lib/pickle.py | 2 +-
Lib/test/pickletester.py | 8 ++++++++
Misc/NEWS | 2 ++
Modules/_pickle.c | 8 ++++----
4 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/Lib/pickle.py b/Lib/pickle.py
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -903,7 +903,7 @@
orig = self.readline()
rep = orig[:-1]
# Strip outermost quotes
- if rep[0] == rep[-1] and rep[0] in b'"\'':
+ if len(rep) >= 2 and rep[0] == rep[-1] and rep[0] in b'"\'':
rep = rep[1:-1]
else:
raise ValueError("insecure string pickle")
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -609,6 +609,14 @@
b"'abc\"", # open quote and close quote don't match
b"'abc' ?", # junk after close quote
b"'\\'", # trailing backslash
+ # Variations on issue #17710
+ b"'",
+ b'"',
+ b"' ",
+ b"' ",
+ b"' ",
+ b"' ",
+ b'" ',
# some tests of the quoting rules
## b"'abc\"\''",
## b"'\\\\a\'\'\'\\\'\\\\\''",
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,8 @@
Library
-------
+- Issue #17710: Fix pickle raising a SystemError on bogus input.
+
- Issue #17341: Include the invalid name in the error messages from re about
invalid group names.
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4205,7 +4205,7 @@
if ((len = _Unpickler_Readline(self, &s)) < 0)
return -1;
- if (len < 3)
+ if (len < 2)
return bad_readline();
if ((s = strdup(s)) == NULL) {
PyErr_NoMemory();
@@ -4213,14 +4213,14 @@
}
/* Strip outermost quotes */
- while (s[len - 1] <= ' ')
+ while (len > 0 && s[len - 1] <= ' ')
len--;
- if (s[0] == '"' && s[len - 1] == '"') {
+ if (len > 1 && s[0] == '"' && s[len - 1] == '"') {
s[len - 1] = '\0';
p = s + 1;
len -= 2;
}
- else if (s[0] == '\'' && s[len - 1] == '\'') {
+ else if (len > 1 && s[0] == '\'' && s[len - 1] == '\'') {
s[len - 1] = '\0';
p = s + 1;
len -= 2;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list