File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -227,8 +227,22 @@ def test_fuzz(self):
227227 pass
228228
229229 def test_loads_recursion (self ):
230- s = 'c' + ('X' * 4 * 4 ) + '{' * 2 ** 20
231- self .assertRaises (ValueError , marshal .loads , s )
230+ def run_tests (N , check ):
231+ # (((...None...),),)
232+ check (b'(\x01 \x00 \x00 \x00 ' * N + b'N' )
233+ # [[[...None...]]]
234+ check (b'[\x01 \x00 \x00 \x00 ' * N + b'N' )
235+ # {None: {None: {None: ...None...}}}
236+ check (b'{N' * N + b'N' + b'0' * N )
237+ # frozenset([frozenset([frozenset([...None...])])])
238+ check (b'>\x01 \x00 \x00 \x00 ' * N + b'N' )
239+ # Check that the generated marshal data is valid and marshal.loads()
240+ # works for moderately deep nesting
241+ run_tests (100 , marshal .loads )
242+ # Very deeply nested structure shouldn't blow the stack
243+ def check (s ):
244+ self .assertRaises (ValueError , marshal .loads , s )
245+ run_tests (2 ** 20 , check )
232246
233247 def test_recursion_limit (self ):
234248 # Create a deeply nested structure.
You can’t perform that action at this time.
0 commit comments