Commit be92971b authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #17710: Fix cPickle raising a SystemError on bogus input.

parent 108d1b4a
......@@ -962,7 +962,7 @@ class Unpickler:
rep = self.readline()[:-1]
for q in "\"'": # double or single quote
if rep.startswith(q):
if not rep.endswith(q):
if len(rep) < 2 or not rep.endswith(q):
raise ValueError, "insecure string pickle"
rep = rep[len(q):-len(q)]
break
......
......@@ -538,6 +538,8 @@ class AbstractPickleTests(unittest.TestCase):
"'abc\"", # open quote and close quote don't match
"'abc' ?", # junk after close quote
"'\\'", # trailing backslash
"'", # issue #17710
"' ", # issue #17710
# some tests of the quoting rules
#"'abc\"\''",
#"'\\\\a\'\'\'\\\'\\\\\''",
......
......@@ -28,6 +28,8 @@ Core and Builtins
Library
-------
- Issue #17710: Fix cPickle raising a SystemError on bogus input.
- Issue #17341: Include the invalid name in the error messages from re about
invalid group names.
......
......@@ -3643,17 +3643,19 @@ load_string(Unpicklerobject *self)
/* 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;
} else
}
else
goto insecure;
/********************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment