Skip to content
16 changes: 16 additions & 0 deletions Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,14 @@ def test_resize_term(self):
self.assertEqual(curses.LINES, lines)
self.assertEqual(curses.COLS, cols)

with self.assertRaises(OverflowError):
curses.resize_term(35000, 1)
with self.assertRaises(OverflowError):
curses.resize_term(1, 35000)
# GH-120378: Overflow failure in resize_term() causes refresh to fail
tmp = curses.initscr()
tmp.erase()

@requires_curses_func('resizeterm')
def test_resizeterm(self):
curses.update_lines_cols()
Expand All @@ -1095,6 +1103,14 @@ def test_resizeterm(self):
self.assertEqual(curses.LINES, lines)
self.assertEqual(curses.COLS, cols)

with self.assertRaises(OverflowError):
curses.resizeterm(35000, 1)
with self.assertRaises(OverflowError):
curses.resizeterm(1, 35000)
# GH-120378: Overflow failure in resizeterm() causes refresh to fail
tmp = curses.initscr()
tmp.erase()

def test_ungetch(self):
curses.ungetch(b'A')
self.assertEqual(self.stdscr.getkey(), 'A')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash related to an integer overflow in :func:`curses.resizeterm`
and :func:`curses.resize_term`.
16 changes: 8 additions & 8 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4113,9 +4113,9 @@ NoArgNoReturnFunctionBody(resetty)
/*[clinic input]
_curses.resizeterm

nlines: int
nlines: short
Height.
ncols: int
ncols: short
Width.
/

Expand All @@ -4126,8 +4126,8 @@ window dimensions (in particular the SIGWINCH handler).
[clinic start generated code]*/

static PyObject *
_curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=56d6bcc5194ad055 input=0fca02ebad5ffa82]*/
_curses_resizeterm_impl(PyObject *module, short nlines, short ncols)
/*[clinic end generated code: output=4de3abab50c67f02 input=414e92a63e3e9899]*/
{
PyObject *result;

Expand All @@ -4149,9 +4149,9 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
/*[clinic input]
_curses.resize_term

nlines: int
nlines: short
Height.
ncols: int
ncols: short
Width.
/

Expand All @@ -4165,8 +4165,8 @@ without additional interaction with the application.
[clinic start generated code]*/

static PyObject *
_curses_resize_term_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=9e26d8b9ea311ed2 input=2197edd05b049ed4]*/
_curses_resize_term_impl(PyObject *module, short nlines, short ncols)
/*[clinic end generated code: output=46c6d749fa291dbd input=276afa43d8ea7091]*/
{
PyObject *result;

Expand Down
98 changes: 79 additions & 19 deletions Modules/clinic/_cursesmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading