Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
c221cf3e
Commit
c221cf3e
authored
Jun 14, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce safety check for unpickling.
parent
6053339c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+10
-3
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
c221cf3e
...
...
@@ -7,6 +7,7 @@ cython.declare(PyrexTypes=object, Naming=object, ExprNodes=object, Nodes=object,
error
=
object
,
warning
=
object
,
copy
=
object
,
_unicode
=
object
)
import
copy
import
hashlib
from
.
import
PyrexTypes
from
.
import
Naming
...
...
@@ -1610,10 +1611,14 @@ if VALUE is not None:
else
:
all_members_names
=
sorted
([
e
.
name
for
e
in
all_members
])
checksum
=
'0x%s'
%
hashlib
.
md5
(
' '
.
join
(
all_members_names
).
encode
(
'utf-8'
)).
hexdigest
()[:
7
]
unpickle_func_name
=
'__pyx_unpickle_%s'
%
node
.
class_name
unpickle_func
=
TreeFragment
(
u"""
def %(unpickle_func_name)s(__pyx_type, __pyx_state, %(args)s):
def %(unpickle_func_name)s(__pyx_type, long __pyx_checksum, __pyx_state, %(args)s):
if __pyx_checksum != %(checksum)s:
from pickle import PickleError
raise PickleError("Incompatible checksums (%%s vs %(checksum)s = (%(members)s))" %% __pyx_checksum)
cdef %(class_name)s result
result = %(class_name)s.__new__(__pyx_type)
%(assignments)s
...
...
@@ -1627,6 +1632,8 @@ if VALUE is not None:
return result
"""
%
{
'unpickle_func_name'
:
unpickle_func_name
,
'checksum'
:
checksum
,
'members'
:
', '
.
join
(
all_members_names
),
'class_name'
:
node
.
class_name
,
'assignments'
:
'; '
.
join
(
'result.%s = __pyx_arg_%s'
%
(
v
,
v
)
for
v
in
all_members_names
),
'args'
:
','
.
join
(
'__pyx_arg_%s'
%
v
for
v
in
all_members_names
),
...
...
@@ -1643,8 +1650,8 @@ if VALUE is not None:
state = self.__dict__
else:
state = None
return %s, (type(self), state, %s)
"""
%
(
unpickle_func_name
,
', '
.
join
(
'self.%s'
%
v
for
v
in
all_members_names
)),
return %s, (type(self),
%s,
state, %s)
"""
%
(
unpickle_func_name
,
checksum
,
', '
.
join
(
'self.%s'
%
v
for
v
in
all_members_names
)),
level
=
'c_class'
,
pipeline
=
[
NormalizeTree
(
None
)]).
substitute
({})
pickle_func
.
analyse_declarations
(
node
.
scope
)
self
.
visit
(
pickle_func
)
...
...
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