@@ -1344,6 +1344,41 @@ def test_bad_newobj_ex(self):
1344
1344
self .check_unpickling_error (error , b'cbuiltins\n int\n N}\x92 .' )
1345
1345
self .check_unpickling_error (error , b'cbuiltins\n int\n )N\x92 .' )
1346
1346
1347
+ def test_bad_state (self ):
1348
+ c = C ()
1349
+ c .x = None
1350
+ base = b'c__main__\n C\n )\x81 '
1351
+ self .assertEqual (self .loads (base + b'}X\x01 \x00 \x00 \x00 xNsb.' ), c )
1352
+ self .assertEqual (self .loads (base + b'N}X\x01 \x00 \x00 \x00 xNs\x86 b.' ), c )
1353
+ # non-hashable dict key
1354
+ self .check_unpickling_error (TypeError , base + b'}]Nsb.' )
1355
+ # state = list
1356
+ error = (pickle .UnpicklingError , AttributeError )
1357
+ self .check_unpickling_error (error , base + b'](}}eb.' )
1358
+ # state = 1-tuple
1359
+ self .check_unpickling_error (error , base + b'}\x85 b.' )
1360
+ # state = 3-tuple
1361
+ self .check_unpickling_error (error , base + b'}}}\x87 b.' )
1362
+ # non-hashable slot name
1363
+ self .check_unpickling_error (TypeError , base + b'}}]Ns\x86 b.' )
1364
+ # non-string slot name
1365
+ self .check_unpickling_error (TypeError , base + b'}}NNs\x86 b.' )
1366
+ # dict = True
1367
+ self .check_unpickling_error (error , base + b'\x88 }\x86 b.' )
1368
+ # slots dict = True
1369
+ self .check_unpickling_error (error , base + b'}\x88 \x86 b.' )
1370
+
1371
+ class BadKey1 :
1372
+ count = 1
1373
+ def __hash__ (self ):
1374
+ if not self .count :
1375
+ raise CustomError
1376
+ self .count -= 1
1377
+ return 42
1378
+ __main__ .BadKey1 = BadKey1
1379
+ # bad hashable dict key
1380
+ self .check_unpickling_error (CustomError , base + b'}c__main__\n BadKey1\n )\x81 Nsb.' )
1381
+
1347
1382
def test_bad_stack (self ):
1348
1383
badpickles = [
1349
1384
b'.' , # STOP
0 commit comments