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: Pasting 900000 chars into a tk Entry widget fails
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, soufiane.boussali, terry.reedy
Priority: low Keywords:

Created on 2016-01-20 21:14 by soufiane.boussali, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
poc.py soufiane.boussali, 2016-01-20 21:14
py2.7.11.png soufiane.boussali, 2016-01-20 21:14 screenshot
py2.7.11.png soufiane.boussali, 2016-01-21 21:19
Messages (7)
msg258732 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-01-21 03:20
'\x41' == 'A'.  I don't know what 'BOF' has to do with the character 'A' or a string of them.

A python or pythonw process 'hanging' does not itself mean that there is a buffer overflow, though I can understand why you suspect it.  Python itself is pretty much immune from buffer overflows, but C code is not ;-).

IDLE crashing is not necessarily an IDLE issue.  IDLE is a application written in Python, including tkinter, which runs tcl/tk code.  It is just as vulnerable to Python, tkinter, and tcl/tk bugs and liminations as any other application.  This appears to be an issue about the limitations of the tcl/tk Entry widget.

When I followed the procedure posted with 3.5.1 on 64 bit Win 10 and pasted the megastring into the tk Entry box, the box stayed blank and a blue circle 'waiting' cursor appeared.  Even if the string was copied from the clipboard into process memory, it exceeded the (undocumented?) limits of the widget.

This behavior can be reproduced independently of IDLE with

import tkinter as tk
root = tk.Tk()
entry = tk.Entry(root)
entry.pack()
root.mainloop()

The latter has been waiting for several minutes.  This does not surprise me.

When I clicked the Search dialog Find-next button, the dialog box turned the whitish gray, all too familiar to me, that indicates that a process is no longer responsive.  This also does not surprise me.  The click causes the associated Python callback to be called.  It tries to get the Entry box text that is likely not available, compile it as a regex with re, and then search the editor text. 

Since we do not control tk Entry widgets, I am inclined to close this as '3rd party'.  Serhiy, what do you think?

PS: the test Entry box is still waiting.  Trying to close it fails and brings up a 'Python is not responding' box as in the screenshot.  I has to kill the process with Task Manager, just as with the IDLE Search window.
msg258745 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-21 08:55
I can't reproduce the issue on Linux with the Entry widget, but can reproduce it with the Text widget. The difference is that the Text widget wraps its content on multiple lines. Looks the code for dynamical splitting the text on lines has quadratic (or larger) complexity. IDLE itself already suffers from similar issue for output text (issue1442493).

For issue1442493 we can preprocess output text. I don't know if we can add a handler for preprocessing pasted text, and wherever it is worth to do. Even if this is possible, new code can be too complex for such corner case.
msg258767 - (view) Author: Soufiane BOUSSALI (soufiane.boussali) * Date: 2016-01-21 21:19
The Function Find In Python IDLE 2.7.11 Affected To Crash Python Environnement On Windows Platform
msg258780 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-01-22 00:49
Soufiane, when a core developer (indicated by the Python icon after the name) changes a header, do not change it back.  Comment on the change if you want, but leave it as is.

My revised title accurately describes the core problem: the paste operation does not complete after the 10-15 minutes I allowed; I suspect and presume that it never will.  Asking tk to do something else while the pasting is ongoing or hung results in a crash.

Serhiy, I am puzzled that you added IDLE back as a component.  I demonstrated that the symptom can be reproduced with no involvement of idlelib at all.  I only left this open for you to decide if a) tkinter is involved and b) if you might want to change tkinter in response.  I otherwise consider this issue outside of reasonable expectations, equivalent to the won't-fix fact that CPython will not compile, for instance, a machine-generated tuple display nested 100,000 levels deep.
msg258794 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-22 11:28
I want to say that may be we can make a workaround for this issue in IDLE if it is worth. The "wont fix" resolution looks reasonable to me, but this doesn't mean that the issue couldn't be solved in principle (though the solution can be very costly). I'm closing this issue, but only because we have too  much other open IDLE issues, and with very good chance this issue will never solved.

Other issue is that it would be nice to make IDLE and Tkinter more responsive. Allow to interrupt long-running Tk operation and ask the user to save his files before quit. But this is separate issue.
msg258841 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-01-22 22:38
I understand now what you were thinking. Even a timeout might not work for this because one could paste and within a second click Find-next and likely trigger the crash.

I tested printing, copying, and finding 'a'*10000 and it worked.  I think this is good enough, with probability 1.0, for any real use ;-).
msg258872 - (view) Author: Soufiane BOUSSALI (soufiane.boussali) * Date: 2016-01-23 17:17
thanks terry reedy For Fixing This Stack Overflow :)
History
Date User Action Args
2022-04-11 14:58:26adminsetgithub: 70357
2016-01-23 17:17:09soufiane.boussalisetmessages: + msg258872
2016-01-22 22:38:36terry.reedysetmessages: + msg258841
2016-01-22 11:28:36serhiy.storchakasetstatus: open -> closed
resolution: wont fix
messages: + msg258794

stage: resolved
2016-01-22 00:49:28terry.reedysetmessages: + msg258780
components: - IDLE
title: Crash Python IDLE 2.7.11 -> Pasting 900000 chars into a tk Entry widget fails
2016-01-21 21:19:49soufiane.boussalisetfiles: + py2.7.11.png

messages: + msg258767
title: Pasting 900000 chars into a tk Entry widget fails -> Crash Python IDLE 2.7.11
2016-01-21 08:55:10serhiy.storchakasetpriority: normal -> low
versions: + Python 3.6
messages: + msg258745

components: + IDLE
type: crash -> behavior
2016-01-21 03:20:36terry.reedysettitle: Buffer OverFlow in IDLE 2.7.11 -> Pasting 900000 chars into a tk Entry widget fails
nosy: + serhiy.storchaka, - kbk, roger.serwy

messages: + msg258732

versions: + Python 3.5
components: + Tkinter, - IDLE
2016-01-20 22:42:17soufiane.boussalisettitle: Buffer OverFlow in IDLE -> Buffer OverFlow in IDLE 2.7.11
2016-01-20 21:27:58SilentGhostsetnosy: + terry.reedy, kbk, roger.serwy

title: Buffer OverFlow -> Buffer OverFlow in IDLE
2016-01-20 21:14:42soufiane.boussalisetfiles: + py2.7.11.png
2016-01-20 21:14:07soufiane.boussalicreate