@@ -1710,6 +1710,20 @@ def __index__(self):
17101710 with self .assertRaises (IndexError ):
17111711 victim [1 ] = ShrinkIndex () # Original index 1 should now be out of bounds
17121712
1713+ def test_clear_array_float (victim ):
1714+ """Test array clearing scenario using __float__ method"""
1715+ class EvilFloat :
1716+ def __float__ (self ):
1717+ # Re-entrant mutation: clear the array while __setitem__
1718+ # still holds a pointer to the pre-clear buffer.
1719+ victim .clear ()
1720+ return 0.0
1721+
1722+ with self .assertRaises (IndexError ):
1723+ victim [1 ] = EvilFloat ()
1724+
1725+ self .assertEqual (len (victim ), 0 )
1726+
17131727 # Test various array types
17141728 test_clear_array (array .array ('b' , [0 ] * 64 ))
17151729 test_shrink_array (array .array ('b' , [1 , 2 , 3 ]))
@@ -1719,8 +1733,13 @@ def __index__(self):
17191733 test_clear_array (array .array ('i' , [1 , 2 , 3 ]))
17201734 test_clear_array (array .array ('l' , [1 , 2 , 3 ]))
17211735 test_clear_array (array .array ('q' , [1 , 2 , 3 ]))
1722- test_clear_array (array .array ('f' , [1.0 , 2.0 , 3.0 ]))
1723- test_clear_array (array .array ('d' , [1.0 , 2.0 , 3.0 ]))
1736+ test_clear_array (array .array ('I' , [1 , 2 , 3 ]))
1737+ test_clear_array (array .array ('L' , [1 , 2 , 3 ]))
1738+ test_clear_array (array .array ('Q' , [1 , 2 , 3 ]))
1739+
1740+ # Test float arrays with __float__ method
1741+ test_clear_array_float (array .array ('f' , [1.0 , 2.0 , 3.0 ]))
1742+ test_clear_array_float (array .array ('d' , [1.0 , 2.0 , 3.0 ]))
17241743
17251744
17261745if __name__ == "__main__" :
0 commit comments