-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Infinite recursion in curses.textpad.Textbox #57260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The attached patch fixes two bugs which manifest as infinite recursion in _insert_printable_char() of Textbox. First, the previous implementation of _insert_printable_char() used recursion to move characters when inserting a character. Thus, any Textpad which had an area greater than the interpreter's maximum recursion limit would crash. A minimal test case is the following: #!/usr/bin/python
import curses
from curses.textpad import Textbox
def main(stdscr):
box = Textbox(stdscr, insert_mode=True)
box.stripspaces = True
while 1:
cmd = box.edit()
if cmd == 'q':
break
curses.wrapper(main) Run that script in a terminal with area (i.e. $LINES * $COLUMNS) > 1000 (the default max recursion limit), press any key and be greeted by a stack trace. The patch changes the implementation of _insert_printable_char() to be iterative, thus avoiding the infinite recursion. Second, when the underlying curses window was resized to be smaller than it was when the Textpad was created, pressing any key would result in infinite recursion (or with the new method, an infinite loop). The patch also changes Textpad so that instead of keeping the underlying window's size as instance attributes of this Textpad, Textpad asks the underlying window its size every time Textpad needs to know, allowing the underlying window to be resized at will. I've verified this bug is in 2.7.1 and 3.2. Let me know if you need anything else. |
Would you be able to produce a unit test which fails before your patch is applied, but succeeds after applying your changes? That'll make your changes more likely to get accepted. |
Attached is a patch which contains a testcase as well. A few notes about this testcase:
Comments are appreciated! |
Hi, any movement on this? |
Any progress on this? Its Dec 2016 and this bug is still around. There's a patch and a patch with tests. The problem is well-understood. I'm not sure what the holdup is, but it would be great to get fixed! |
The patch doesn't apply cleanly anymore so the next step would be to provide an updated patch. By the way, I can reproduce the first bug, but not the second one. If the second bug can't be reproducible anymore, we might need a simpler patch. |
I can reproduce the second bug too. Here is updated patch. The main difference is that it preserves maxx and maxy attributes and support them up to date. |
New changeset b446a4aab9cf by Serhiy Storchaka in branch '3.5': New changeset d87771d1c1e6 by Serhiy Storchaka in branch '2.7': New changeset ea87e00a3e89 by Serhiy Storchaka in branch '3.6': New changeset ea7f22cf9c8c by Serhiy Storchaka in branch 'default': |
Thank you for your contribution Tycho. |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: