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
6eb7bede
Commit
6eb7bede
authored
May 18, 2007
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify neither dumps or loads overflow the stack and segfault.
parent
88d96ade
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletion
+21
-1
Lib/test/test_marshal.py
Lib/test/test_marshal.py
+21
-1
No files found.
Lib/test/test_marshal.py
View file @
6eb7bede
...
...
@@ -220,10 +220,30 @@ class BugsTestCase(unittest.TestCase):
except
Exception
:
pass
def
test_recursion
(
self
):
def
test_
loads_
recursion
(
self
):
s
=
'c'
+
(
'X'
*
4
*
4
)
+
'{'
*
2
**
20
self
.
assertRaises
(
ValueError
,
marshal
.
loads
,
s
)
def
test_recursion_limit
(
self
):
# Create a deeply nested structure.
head
=
last
=
[]
# The max stack depth should match the value in Python/marshal.c.
MAX_MARSHAL_STACK_DEPTH
=
2000
for
i
in
range
(
MAX_MARSHAL_STACK_DEPTH
-
2
):
last
.
append
([
0
])
last
=
last
[
-
1
]
# Verify we don't blow out the stack with dumps/load.
data
=
marshal
.
dumps
(
head
)
new_head
=
marshal
.
loads
(
data
)
# Don't use == to compare objects, it can exceed the recursion limit.
self
.
assertEqual
(
len
(
new_head
),
len
(
head
))
self
.
assertEqual
(
len
(
new_head
[
0
]),
len
(
head
[
0
]))
self
.
assertEqual
(
len
(
new_head
[
-
1
]),
len
(
head
[
-
1
]))
last
.
append
([
0
])
self
.
assertRaises
(
ValueError
,
marshal
.
dumps
,
head
)
def
test_main
():
test_support
.
run_unittest
(
IntTestCase
,
FloatTestCase
,
...
...
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