Skip to content
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

Infinite recursion in curses.textpad.Textbox #57260

Closed
tycho mannequin opened this issue Sep 28, 2011 · 9 comments
Closed

Infinite recursion in curses.textpad.Textbox #57260

tycho mannequin opened this issue Sep 28, 2011 · 9 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tycho
Copy link
Mannequin

tycho mannequin commented Sep 28, 2011

BPO 13051
Nosy @vstinner, @briancurtin, @berkerpeksag, @serhiy-storchaka, @rxcomm
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • textpad_resize.patch
  • textpad-recursion-fix.patch
  • textpad-recursion-fix2.patch
  • Note: 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-12-28.08:24:41.251>
    created_at = <Date 2011-09-28.00:47:10.643>
    labels = ['3.7', 'type-bug', 'library']
    title = 'Infinite recursion in curses.textpad.Textbox'
    updated_at = <Date 2017-03-31.16:36:21.131>
    user = 'https://bugs.python.org/tycho'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:21.131>
    actor = 'dstufft'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-12-28.08:24:41.251>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2011-09-28.00:47:10.643>
    creator = 'tycho'
    dependencies = []
    files = ['23249', '24061', '45945']
    hgrepos = []
    issue_num = 13051
    keywords = ['patch']
    message_count = 9.0
    messages = ['144559', '149892', '149920', '151947', '283397', '283458', '283506', '284163', '284164']
    nosy_count = 7.0
    nosy_names = ['vstinner', 'brian.curtin', 'python-dev', 'berker.peksag', 'tycho', 'serhiy.storchaka', 'rxcomm']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13051'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @tycho
    Copy link
    Mannequin Author

    tycho mannequin commented Sep 28, 2011

    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.

    @tycho tycho mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir labels Sep 28, 2011
    @briancurtin
    Copy link
    Member

    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.

    @tycho
    Copy link
    Mannequin Author

    tycho mannequin commented Dec 20, 2011

    Attached is a patch which contains a testcase as well. A few notes about this testcase:

    1. I couldn't figure out how to get it to run correctly after all the other tests had run, so I had to run it first. This seems lame. One possible fix is to run each testcase in curses.wrapper; I'd be happy to change this patch to do that if it's more acceptable.

    2. This testcase only tests one of the two bugs this patch fixes. The other seems much harder to write a testcase for, since you have to have a terminal such that curses.LINES * curses.COLUMS > sys.getrecursionlimit(). If there's a good way to guarantee this, I'd be happy to write a testcase for it.

    Comments are appreciated!

    @tycho
    Copy link
    Mannequin Author

    tycho mannequin commented Jan 25, 2012

    Hi, any movement on this?

    @rxcomm
    Copy link
    Mannequin

    rxcomm mannequin commented Dec 16, 2016

    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!

    @berkerpeksag
    Copy link
    Member

    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.

    @berkerpeksag berkerpeksag added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 17, 2016
    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka serhiy-storchaka self-assigned this Dec 28, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 28, 2016

    New changeset b446a4aab9cf by Serhiy Storchaka in branch '3.5':
    Issue bpo-13051: Fixed recursion errors in large or resized curses.textpad.Textbox.
    https://hg.python.org/cpython/rev/b446a4aab9cf

    New changeset d87771d1c1e6 by Serhiy Storchaka in branch '2.7':
    Issue bpo-13051: Fixed recursion errors in large or resized curses.textpad.Textbox.
    https://hg.python.org/cpython/rev/d87771d1c1e6

    New changeset ea87e00a3e89 by Serhiy Storchaka in branch '3.6':
    Issue bpo-13051: Fixed recursion errors in large or resized curses.textpad.Textbox.
    https://hg.python.org/cpython/rev/ea87e00a3e89

    New changeset ea7f22cf9c8c by Serhiy Storchaka in branch 'default':
    Issue bpo-13051: Fixed recursion errors in large or resized curses.textpad.Textbox.
    https://hg.python.org/cpython/rev/ea7f22cf9c8c

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your contribution Tycho.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants