-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
curses segfault resizing window #80105
Comments
To provoke a segmentation fault, run the attached, then grab the top or Expected error, which is what happens when dragging the left or right edge Traceback (most recent call last):
File "cursesfault.py", line 12, in <module>
curses.wrapper(main)
File "/usr/lib64/python3.6/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "cursesfault.py", line 9, in main
w.addstr(0, 0, box)
_curses.error: addwstr() returned ERR Actual error message varies a little. It's either:
Or:
Or:
Possibly relates to bpo-15581 --- Python 2.7.14 and 3.6.5 uname -a |
I am able to confirm the repro, I haven't been able to find the root cause of it yet though. Trying to dig into it. |
I'm still debugging this but it may be an off-by-one error in ncurses, wresize.c. I've found that if I modify the following section in ncurses, our problem goes away: /*
* Dispose of unwanted memory.
*/
if (!(win->_flags & _SUBWIN)) {
if (ToCols == size_x) {
for (row = ToLines + 1; row <= size_y; row++) {
free(win->_line[row].text);
}
} else {
for (row = 0; row <= size_y; row++) {
free(win->_line[row].text);
}
}
}
free(win->_line);
win->_line = new_lines;
Replacing:
for (row = ToLines + 1; row <= size_y; row++) {
with:
for (row = ToLines + 2; row <= size_y; row++) { fixes this error. ToLines is a parameter passed in to wresize. wresize will reuse ToLines number of rows from the old structure in the new structure. Due to that, I think that the chances are good that it is ncurses which is at fault here. I will try to rewrite the test case into a C program and then submit a bug report to ncurses upstream. I'm not sure that there's a way we can work around this until that's fixed. |
I've diagnosed this a bit further and have a workaround for you. It appears that using addstr() with a string with embedded newlines is a piece of the problem. If I modify your example program so that we add each line as a separate string instead of adding them as a single string with embedded newlines, we get the ncurses ERR on resize instead of a segfault: import curses
def main(stdscr):
y, x = curses.LINES//3, curses.COLS//3 # size is arbitrary
box = '\n'.join('+'*x for _ in range(y))
w = stdscr.subwin(y, x+1, y, x)
while True:
new_box = box[:]
w.clear()
for offset, line in enumerate(box.splitlines()):
w.addstr(offset, 0, line)
w.getch() # not required, just avoids a hot loop
curses.wrapper(main) I don't see anything in the curses specification that forbids embedded newlines in the string to addstr(), though, so I am still thinking that this is a bug in ncurses. |
My upstream (ncurses) bug report: http://lists.gnu.org/archive/html/bug-ncurses/2019-05/msg00010.html |
Hi Josiah, I've tested my sample program and it looks like the segmentation fault is fixed with ncurses-6.1-20190511: http://lists.gnu.org/archive/html/bug-ncurses/2019-05/msg00013.html Are you able to give that a try and see whether it resolves the issue for you as well? For the Core devs; Assuming this is fixed in a newer ncurses, how would you like to proceed with this bug? I have a documentation PR to tell people about the bug in ncurses and the workaround: #13209 I can update that to mention the version of ncurses that this is fixed in if you want that. Other than that, I'm not sure what more we can do. |
Thank you for all the work you did on this Toshio! I think we are good to close this issue. |
Yes, thanks Toshio and Lisa and sorry for the slow response. I just now built a Python 3.7.3 against ncurses-6.1-20190511 and can confirm it resolved the issue. |
1 similar comment
Yes, thanks Toshio and Lisa and sorry for the slow response. I just now built a Python 3.7.3 against ncurses-6.1-20190511 and can confirm it resolved the issue. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: