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: Bad assertion in _tkinter.c
Type: Stage:
Components: Tkinter Versions: Python 3.0, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: brett.cannon, christian.heimes, facundobatista, gvanrossum, thyrsus
Priority: high Keywords: patch

Created on 2007-10-18 23:26 by thyrsus, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter.diff gvanrossum, 2008-01-03 21:49
Messages (11)
msg56546 - (view) Author: Stephen P. Schaefer (thyrsus) Date: 2007-10-18 23:26
The following fails with python 2.5 as built by Fedora 7:

t2.py:
import sys, Tkinter
Tkinter.Button(text=u"").pack( )
Tkinter.mainloop( )

$ python t2.py
python: ./Modules/_tkinter.c:941: AsObj: Assertion `size < size *
sizeof(Tcl_UniChar)' failed.
Aborted

The following patch corrects the problem:

--- Python-2.5-fc7/Modules/_tkinter.c   2006-08-11 22:33:36.000000000 -0400
+++ Python-2.5/Modules/_tkinter.c       2007-10-18 18:44:40.000000000 -0400
@@ -938,7 +938,7 @@
 #if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX == 3
                Tcl_UniChar *outbuf;
                Py_ssize_t i;
-               assert(size < size * sizeof(Tcl_UniChar));
+               assert(size == 0 || size < size * sizeof(Tcl_UniChar));
                outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar));
                if (!outbuf) {
                        PyErr_NoMemory();
msg56547 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-10-19 00:55
Patch is inlined in a comment.
msg56743 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2007-10-25 13:09
Really do not understand that assert. It says:

    assert(size < size * sizeof(Tcl_UniChar));

For that to be true, considering size to be positive, the result of
sizeof needs to be greater than 0.

If you modify it, and also accepts it to be 0, and considering that the
result of sizeof won't be negative, what is the point of keeping the assert?
msg59105 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-02 22:16
So what's the correct fix? Skip the whole block if size==0?
msg59107 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-02 23:08
I've hit the same bug today. I vote for the removal of the assert() and
a skip of the entire block if size == 0. I don't see what the assert()
should test.
msg59158 - (view) Author: Stephen P. Schaefer (thyrsus) Date: 2008-01-03 21:03
I'm not sure of the scope of the "block" to which you're referring.  As
patched, the code returns a Tcl_Obj representing 0 length unicode
string, which appears to me to be the correct behavior, and works for
the applications I use (originally developed in python 2.3 and python
2.4).  I doubt that it's worth special-casing away the call for a 0
length outbuf, the skipped for loop, plus the call to free the 0 length
outbuf.
msg59163 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-03 21:42
I suspect the assert is an overflow check. But since asserts are
compiled into no-ops unless we're using debug mode, I don't see the
point of using an assert.  Just to close the issue I'll replace it with
a proper overflow check.
msg59164 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-03 21:49
Before I make a fool out of myself, what do folks think of this patch?
msg59168 - (view) Author: Stephen P. Schaefer (thyrsus) Date: 2008-01-03 22:14
It looks good to me (to the extent that means anything).  I'm doing an
rpmbuild now with your patch applied to the Fedora 7 .src.rpm, and I'll
start using the result on my workstation ASAP.
msg59182 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-03 23:55
Committed revision 59685.  (2.5.2 branch)
Committed revision 59686.  (2.6 trunk)
msg59192 - (view) Author: Stephen P. Schaefer (thyrsus) Date: 2008-01-04 00:35
Mr. van Rossum's patch, applied to the Fedora 7 .src.rpm, is working for me.
History
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45642
2008-01-04 00:35:37thyrsussetmessages: + msg59192
2008-01-03 23:55:10gvanrossumsetstatus: open -> closed
resolution: fixed
messages: + msg59182
2008-01-03 22:14:05thyrsussetmessages: + msg59168
2008-01-03 21:49:22gvanrossumsetfiles: + tkinter.diff
messages: + msg59164
2008-01-03 21:42:26gvanrossumsetpriority: high
assignee: gvanrossum
messages: + msg59163
2008-01-03 21:03:12thyrsussetmessages: + msg59158
2008-01-02 23:08:49christian.heimessetnosy: + christian.heimes
messages: + msg59107
versions: + Python 2.6, Python 3.0
2008-01-02 22:16:30gvanrossumsetnosy: + gvanrossum
messages: + msg59105
2008-01-02 19:55:06loewislinkissue1721 superseder
2007-10-25 13:09:53facundobatistasetnosy: + facundobatista
messages: + msg56743
2007-10-19 00:55:59brett.cannonsetkeywords: + patch
nosy: + brett.cannon
messages: + msg56547
2007-10-18 23:26:25thyrsuscreate