[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Failure of resizeterm() causes subsequent call with stdscr to crash
From: |
Thomas Dickey |
Subject: |
Re: Failure of resizeterm() causes subsequent call with stdscr to crash |
Date: |
Wed, 25 Sep 2024 16:20:40 -0400 |
On Wed, Sep 25, 2024 at 10:35:24AM -0400, Bill Gray wrote:
> On 9/25/24 08:29, Peter Bierma wrote:> This was reported downstream as a bug
> in Python's curses module. See the
> > issue there: https://github.com/python/cpython/issues/120378
> > <https://github.com/python/cpython/issues/120378>
> >
> > It seems that calling resizeterm() with some ridiculous resolution
> > (35000x1 in the CPython issue) causes stdscr to break (i.e., a crash). A
> > small reproducer:
> >
> > #include <curses.h> // or ncurses.h
> >
> > int
> > main(void)
> > {
> > initscr();
> > if (resizeterm(35000, 1) < 0) {
> > puts("resizeterm() failed, trying to reset");
> > }
> > wrefresh(stdscr); // Segfault!
> > return 0;
> > }
>
> The limit appears to be 32767. 32768 (which, as a signed short, is
> really -32768) fails. Similarly,
>
> win = newwin( 32767, 0, 0, 0);
>
> returns a non-NULL pointer. Go up by one, and win == NULL.
for newwin, I have this crude check for overflow:
static bool
dimension_limit(int value)
{
NCURSES_SIZE_T test = (NCURSES_SIZE_T) value;
return (test == value && value > 0);
}
though a hard limit would suffice (agreeing that terminals with 32k lines
and columns are hard to come by - but pads should be less limited).
> I can't come up with a reason why you'd have such a large window. But
> then again, I also can't come up with a reason why it should fail.
overlooked :-(
Unless specially configured, ncurses's using short internally -- as well as in
the WINDOW struct, because that was from the original curses implementation,
based on the terminfo format.
I made the sizes configurable to an int long ago (2000), but no packager
followed up on that, and changing it would have changed ABI. Later (2007),
I provided for making WINDOW opaque (which would have allowed changing its
internals), and it got little attention as well.
Changing the default to opaque in ncurses 6.5 has limited effect - I recall
seeing a packager comment that they would override that default.
Now I could have added a limit-check to wresize (looks overdue), but
it's very rare for programmers to do this, and none of those had
reported breakage -- as I recall it, all of those had tried creating
a too-large window with newwin.
--
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net
signature.asc
Description: PGP signature