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: ...@@ -962,7 +962,7 @@ class Unpickler:
rep = self.readline()[:-1] rep = self.readline()[:-1]
for q in "\"'": # double or single quote for q in "\"'": # double or single quote
if rep.startswith(q): if rep.startswith(q):
if not rep.endswith(q): if len(rep) < 2 or not rep.endswith(q):
raise ValueError, "insecure string pickle" raise ValueError, "insecure string pickle"
rep = rep[len(q):-len(q)] rep = rep[len(q):-len(q)]
break break
......
...@@ -538,6 +538,8 @@ class AbstractPickleTests(unittest.TestCase): ...@@ -538,6 +538,8 @@ class AbstractPickleTests(unittest.TestCase):
"'abc\"", # open quote and close quote don't match "'abc\"", # open quote and close quote don't match
"'abc' ?", # junk after close quote "'abc' ?", # junk after close quote
"'\\'", # trailing backslash "'\\'", # trailing backslash
"'", # issue #17710
"' ", # issue #17710
# some tests of the quoting rules # some tests of the quoting rules
#"'abc\"\''", #"'abc\"\''",
#"'\\\\a\'\'\'\\\'\\\\\''", #"'\\\\a\'\'\'\\\'\\\\\''",
......
...@@ -28,6 +28,8 @@ Core and Builtins ...@@ -28,6 +28,8 @@ Core and Builtins
Library Library
------- -------
- Issue #17710: Fix cPickle raising a SystemError on bogus input.
- Issue #17341: Include the invalid name in the error messages from re about - Issue #17341: Include the invalid name in the error messages from re about
invalid group names. invalid group names.
......
...@@ -3643,17 +3643,19 @@ load_string(Unpicklerobject *self) ...@@ -3643,17 +3643,19 @@ load_string(Unpicklerobject *self)
/* Strip outermost quotes */ /* Strip outermost quotes */
while (s[len-1] <= ' ') while (len > 0 && s[len-1] <= ' ')
len--; len--;
if(s[0]=='"' && s[len-1]=='"'){ if (len > 1 && s[0]=='"' && s[len-1]=='"') {
s[len-1] = '\0'; s[len-1] = '\0';
p = s + 1 ; p = s + 1 ;
len -= 2; len -= 2;
} else if(s[0]=='\'' && s[len-1]=='\''){ }
else if (len > 1 && s[0]=='\'' && s[len-1]=='\'') {
s[len-1] = '\0'; s[len-1] = '\0';
p = s + 1 ; p = s + 1 ;
len -= 2; len -= 2;
} else }
else
goto insecure; 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