Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5c137669
Commit
5c137669
authored
Nov 23, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23914: Fixed SystemError raised by unpickler on broken pickle data.
parent
1456c984
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
4 deletions
+100
-4
Lib/test/pickletester.py
Lib/test/pickletester.py
+73
-1
Lib/test/test_cpickle.py
Lib/test/test_cpickle.py
+2
-0
Lib/test/test_pickle.py
Lib/test/test_pickle.py
+2
-1
Misc/NEWS
Misc/NEWS
+1
-0
Modules/cPickle.c
Modules/cPickle.c
+22
-2
No files found.
Lib/test/pickletester.py
View file @
5c137669
...
...
@@ -7,7 +7,7 @@ import cStringIO
import
pickletools
import
copy_reg
from
test.test_support
import
TestFailed
,
verbose
,
have_unicode
,
TESTFN
from
test.test_support
import
TestFailed
,
verbose
,
have_unicode
,
TESTFN
,
captured_stdout
try
:
from
test.test_support
import
_2G
,
_1M
,
precisionbigmemtest
except
ImportError
:
...
...
@@ -634,6 +634,78 @@ class AbstractUnpickleTests(unittest.TestCase):
self
.
assertEqual
(
unpickled
,
([],)
*
2
)
self
.
assertIs
(
unpickled
[
0
],
unpickled
[
1
])
def
test_bad_stack
(
self
):
badpickles
=
[
b'0.'
,
# POP
b'1.'
,
# POP_MARK
b'2.'
,
# DUP
# b'(2.', # PyUnpickler doesn't raise
b'R.'
,
# REDUCE
b')R.'
,
b'a.'
,
# APPEND
b'Na.'
,
b'b.'
,
# BUILD
b'Nb.'
,
b'd.'
,
# DICT
b'e.'
,
# APPENDS
# b'(e.', # PyUnpickler raises AttributeError
b'i__builtin__
\
n
list
\
n
.'
,
# INST
b'l.'
,
# LIST
b'o.'
,
# OBJ
b'(o.'
,
b'p1
\
n
.'
,
# PUT
b'q
\
x00
.'
,
# BINPUT
b'r
\
x00
\
x00
\
x00
\
x00
.'
,
# LONG_BINPUT
b's.'
,
# SETITEM
b'Ns.'
,
b'NNs.'
,
b't.'
,
# TUPLE
b'u.'
,
# SETITEMS
b'(u.'
,
b'}(Nu.'
,
b'
\
x81
.'
,
# NEWOBJ
b')
\
x81
.'
,
b'
\
x85
.'
,
# TUPLE1
b'
\
x86
.'
,
# TUPLE2
b'N
\
x86
.'
,
b'
\
x87
.'
,
# TUPLE3
b'N
\
x87
.'
,
b'NN
\
x87
.'
,
]
for
p
in
badpickles
:
try
:
self
.
assertRaises
(
self
.
bad_stack_errors
,
self
.
loads
,
p
)
except
:
print
'***'
,
repr
(
p
)
raise
def
test_bad_mark
(
self
):
badpickles
=
[
b'c__builtin__
\
n
list
\
n
)(R.'
,
# REDUCE
b'c__builtin__
\
n
list
\
n
()R.'
,
b']N(a.'
,
# APPEND
b'cexceptions
\
n
ValueError
\
n
)R}(b.'
,
# BUILD
b'cexceptions
\
n
ValueError
\
n
)R(}b.'
,
b'(Nd.'
,
# DICT
b'}NN(s.'
,
# SETITEM
b'}N(Ns.'
,
b'c__builtin__
\
n
list
\
n
)(
\
x81
.'
,
# NEWOBJ
b'c__builtin__
\
n
list
\
n
()
\
x81
.'
,
b'N(
\
x85
.'
,
# TUPLE1
b'NN(
\
x86
.'
,
# TUPLE2
b'N(N
\
x86
.'
,
b'NNN(
\
x87
.'
,
# TUPLE3
b'NN(N
\
x87
.'
,
b'N(NN
\
x87
.'
,
]
for
p
in
badpickles
:
# PyUnpickler prints reduce errors to stdout
try
:
self
.
loads
(
p
)
except
(
IndexError
,
AttributeError
,
TypeError
,
pickle
.
UnpicklingError
):
pass
class
AbstractPickleTests
(
unittest
.
TestCase
):
# Subclass must define self.dumps, self.loads.
...
...
Lib/test/test_cpickle.py
View file @
5c137669
...
...
@@ -51,6 +51,7 @@ class cPickleTests(AbstractUnpickleTests, AbstractPickleTests,
error
=
cPickle
.
BadPickleGet
module
=
cPickle
bad_stack_errors
=
(
cPickle
.
UnpicklingError
,)
class
cPickleUnpicklerTests
(
AbstractUnpickleTests
):
...
...
@@ -63,6 +64,7 @@ class cPickleUnpicklerTests(AbstractUnpickleTests):
self
.
close
(
f
)
error
=
cPickle
.
BadPickleGet
bad_stack_errors
=
(
cPickle
.
UnpicklingError
,)
class
cStringIOCUnpicklerTests
(
cStringIOMixin
,
cPickleUnpicklerTests
):
pass
...
...
Lib/test/test_pickle.py
View file @
5c137669
...
...
@@ -23,17 +23,18 @@ class PickleTests(AbstractUnpickleTests, AbstractPickleTests,
module
=
pickle
error
=
KeyError
bad_stack_errors
=
(
IndexError
,)
class
UnpicklerTests
(
AbstractUnpickleTests
):
error
=
KeyError
bad_stack_errors
=
(
IndexError
,)
def
loads
(
self
,
buf
):
f
=
StringIO
(
buf
)
u
=
pickle
.
Unpickler
(
f
)
return
u
.
load
()
class
PicklerTests
(
AbstractPickleTests
):
def
dumps
(
self
,
arg
,
proto
=
0
,
fast
=
0
):
...
...
Misc/NEWS
View file @
5c137669
...
...
@@ -13,6 +13,7 @@ Core and Builtins
Library
-------
- Issue #23914: Fixed SystemError raised by CPickle unpickler on broken data.
What'
s
New
in
Python
2.7.11
?
============================
...
...
Modules/cPickle.c
View file @
5c137669
...
...
@@ -3945,6 +3945,10 @@ load_obj(Unpicklerobject *self)
Py_ssize_t
i
;
if
((
i
=
marker
(
self
))
<
0
)
return
-
1
;
if
(
self
->
stack
->
length
-
i
<
1
)
return
stackUnderflow
();
if
(
!
(
tup
=
Pdata_popTuple
(
self
->
stack
,
i
+
1
)))
return
-
1
;
PDATA_POP
(
self
->
stack
,
class
);
if
(
class
)
{
...
...
@@ -4496,6 +4500,8 @@ do_append(Unpicklerobject *self, Py_ssize_t x)
static
int
load_append
(
Unpicklerobject
*
self
)
{
if
(
self
->
stack
->
length
-
1
<=
0
)
return
stackUnderflow
();
return
do_append
(
self
,
self
->
stack
->
length
-
1
);
}
...
...
@@ -4503,7 +4509,10 @@ load_append(Unpicklerobject *self)
static
int
load_appends
(
Unpicklerobject
*
self
)
{
return
do_append
(
self
,
marker
(
self
));
Py_ssize_t
i
=
marker
(
self
);
if
(
i
<
0
)
return
-
1
;
return
do_append
(
self
,
i
);
}
...
...
@@ -4515,6 +4524,14 @@ do_setitems(Unpicklerobject *self, Py_ssize_t x)
if
(
!
(
(
len
=
self
->
stack
->
length
)
>=
x
&&
x
>
0
))
return
stackUnderflow
();
if
(
len
==
x
)
/* nothing to do */
return
0
;
if
((
len
-
x
)
%
2
!=
0
)
{
/* Currupt or hostile pickle -- we never write one like this. */
PyErr_SetString
(
UnpicklingError
,
"odd number of items for SETITEMS"
);
return
-
1
;
}
dict
=
self
->
stack
->
data
[
x
-
1
];
...
...
@@ -4542,7 +4559,10 @@ load_setitem(Unpicklerobject *self)
static
int
load_setitems
(
Unpicklerobject
*
self
)
{
return
do_setitems
(
self
,
marker
(
self
));
Py_ssize_t
i
=
marker
(
self
);
if
(
i
<
0
)
return
-
1
;
return
do_setitems
(
self
,
i
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment