Issue #17710: Fix pickle raising a SystemError on bogus input.
This commit is contained in:
parent
ed3cd7e445
commit
3034efdd29
|
@ -951,7 +951,7 @@ class _Unpickler:
|
||||||
rep = orig[:-1]
|
rep = orig[:-1]
|
||||||
for q in (b'"', b"'"): # double or single quote
|
for q in (b'"', b"'"): # 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
|
||||||
|
|
|
@ -609,6 +609,14 @@ class AbstractPickleTests(unittest.TestCase):
|
||||||
b"'abc\"", # open quote and close quote don't match
|
b"'abc\"", # open quote and close quote don't match
|
||||||
b"'abc' ?", # junk after close quote
|
b"'abc' ?", # junk after close quote
|
||||||
b"'\\'", # trailing backslash
|
b"'\\'", # trailing backslash
|
||||||
|
# Variations on issue #17710
|
||||||
|
b"'",
|
||||||
|
b'"',
|
||||||
|
b"' ",
|
||||||
|
b"' ",
|
||||||
|
b"' ",
|
||||||
|
b"' ",
|
||||||
|
b'" ',
|
||||||
# some tests of the quoting rules
|
# some tests of the quoting rules
|
||||||
## b"'abc\"\''",
|
## b"'abc\"\''",
|
||||||
## b"'\\\\a\'\'\'\\\'\\\\\''",
|
## b"'\\\\a\'\'\'\\\'\\\\\''",
|
||||||
|
|
|
@ -29,6 +29,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #17710: Fix pickle 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.
|
||||||
|
|
||||||
|
|
|
@ -4171,7 +4171,7 @@ load_string(UnpicklerObject *self)
|
||||||
|
|
||||||
if ((len = _Unpickler_Readline(self, &s)) < 0)
|
if ((len = _Unpickler_Readline(self, &s)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (len < 3)
|
if (len < 2)
|
||||||
return bad_readline();
|
return bad_readline();
|
||||||
if ((s = strdup(s)) == NULL) {
|
if ((s = strdup(s)) == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
|
@ -4179,14 +4179,14 @@ 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;
|
||||||
|
|
Loading…
Reference in New Issue