@@ -1357,6 +1357,41 @@ def test_bad_newobj_ex(self):
13571357 self .check_unpickling_error (error , b'cbuiltins\n int\n N}\x92 .' )
13581358 self .check_unpickling_error (error , b'cbuiltins\n int\n )N\x92 .' )
13591359
1360+ def test_bad_state (self ):
1361+ c = C ()
1362+ c .x = None
1363+ base = b'c__main__\n C\n )\x81 '
1364+ self .assertEqual (self .loads (base + b'}X\x01 \x00 \x00 \x00 xNsb.' ), c )
1365+ self .assertEqual (self .loads (base + b'N}X\x01 \x00 \x00 \x00 xNs\x86 b.' ), c )
1366+ # non-hashable dict key
1367+ self .check_unpickling_error (TypeError , base + b'}]Nsb.' )
1368+ # state = list
1369+ error = (pickle .UnpicklingError , AttributeError )
1370+ self .check_unpickling_error (error , base + b'](}}eb.' )
1371+ # state = 1-tuple
1372+ self .check_unpickling_error (error , base + b'}\x85 b.' )
1373+ # state = 3-tuple
1374+ self .check_unpickling_error (error , base + b'}}}\x87 b.' )
1375+ # non-hashable slot name
1376+ self .check_unpickling_error (TypeError , base + b'}}]Ns\x86 b.' )
1377+ # non-string slot name
1378+ self .check_unpickling_error (TypeError , base + b'}}NNs\x86 b.' )
1379+ # dict = True
1380+ self .check_unpickling_error (error , base + b'\x88 }\x86 b.' )
1381+ # slots dict = True
1382+ self .check_unpickling_error (error , base + b'}\x88 \x86 b.' )
1383+
1384+ class BadKey1 :
1385+ count = 1
1386+ def __hash__ (self ):
1387+ if not self .count :
1388+ raise CustomError
1389+ self .count -= 1
1390+ return 42
1391+ __main__ .BadKey1 = BadKey1
1392+ # bad hashable dict key
1393+ self .check_unpickling_error (CustomError , base + b'}c__main__\n BadKey1\n )\x81 Nsb.' )
1394+
13601395 def test_bad_stack (self ):
13611396 badpickles = [
13621397 b'.' , # STOP
0 commit comments