This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: list.sort crasher
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: arigo, tim.peters
Priority: normal Keywords: patch

Created on 2002-11-12 15:32 by arigo, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
listsort-patch.diff arigo, 2002-11-12 15:32
Messages (4)
msg41628 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2002-11-12 15:32
Solves the list.sort() crash of
http://www.python.org/sf/453523.

Removes the immutable list trick. Makes the list empty
during sort. Raises ValueError if the (temporarily
empty) list is detected to have been modified at the
end of the sort.
msg41629 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-11-12 21:44
Logged In: YES 
user_id=31435

Assigned to me.
msg41630 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-11-12 22:15
Logged In: YES 
user_id=31435

Thanks, Armin!  It's not ideal, but better than a crash for sure, 
and nobody has had a better idea.

Doc/lib/libstdtypes.tex; new revision: 1.108
Lib/test/test_sort.py; new revision: 1.3
Lib/test/test_types.py; new revision: 1.39
Misc/NEWS; new revision: 1.520
Objects/listobject.c; new revision: 2.141

Note that I fiddled the patch to check ob_size > 0 at the end 
too -- because we use realloc to grow space for lists, it was 
possible for a comparison function to grow empty_ob_item in-
place, and then the mutation wasn't caught.  Ditto if a whole 
bunch of inserts and deletes managed to recycle memory in 
such a way that malloc() just happened to return the same 
address as empty_ob_item a second time.  Those aren't 
hypothetical, cuz I saw them happening when writing a test 
case and wondering why it only caught the mutations *some* 
of the times.  I'm still not sure it's bulletproof mutation 
detection, but the test case triggers every time now, so who 
cares <wink>.
msg41631 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2002-11-13 00:16
Logged In: YES 
user_id=4771

I overlooked the case you mention.  I believe it is now
bulletproof, because no other code in listobject.c will ever
let an empty list have a non-NULL ob_item. But right, who
cares :-)
History
Date User Action Args
2022-04-10 16:05:53adminsetgithub: 37458
2002-11-12 15:32:14arigocreate