@@ -650,8 +650,7 @@ def test_join_reentrant_buffer_mutation(self):
650650 # to that item by mutating the joined sequence.
651651 # See: https://github.com/python/cpython/issues/151295
652652 def make_seq (mutate ):
653- # The mutating item is only referenced from the list slot, so
654- # mutate() drops its last reference mid-join.
653+ # Item is only referenced from the list slot, so mutate() frees it.
655654 class Item :
656655 def __buffer__ (self , flags ):
657656 mutate (seq )
@@ -665,15 +664,12 @@ def __buffer__(self, flags):
665664
666665 for sep in (self .type2test (b'' ), self .type2test (b'::' )):
667666 with self .subTest (sep = sep ):
668- # Clearing the list changes its length, which is reported as a
669- # RuntimeError.
667+ # Changing the list length is reported as a RuntimeError.
670668 seq = make_seq (lambda seq : seq .clear ())
671669 self .assertRaises (RuntimeError , sep .join , seq )
672670
673- # Replacing the item in place keeps the list length unchanged,
674- # so the size-change recheck cannot fire; only keeping the item
675- # alive across __buffer__() prevents the use-after-free, and
676- # the join uses the buffer returned by __buffer__().
671+ # The list length is unchanged, so the size-change recheck
672+ # cannot fire: only keeping the item alive avoids the crash.
677673 def replace (seq ):
678674 seq [1 ] = b'z'
679675 seq = make_seq (replace )
0 commit comments