Skip to content

Commit 2d3087b

Browse files
miss-islingtonZeroIntensitypicnixz
authored
[3.13] gh-120378: Fix crash caused by integer overflow in curses (GH-124555) (#124905)
gh-120378: Fix crash caused by integer overflow in `curses` (GH-124555) This is actually an upstream problem in curses, and has been reported to them already: https://lists.gnu.org/archive/html/bug-ncurses/2024-09/msg00101.html This is a nice workaround in the meantime to prevent the segfault. (cherry picked from commit c2ba931) Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent f5f1d45 commit 2d3087b

File tree

4 files changed

+105
-27
lines changed

4 files changed

+105
-27
lines changed

Lib/test/test_curses.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,14 @@ def test_resize_term(self):
10811081
self.assertEqual(curses.LINES, lines)
10821082
self.assertEqual(curses.COLS, cols)
10831083

1084+
with self.assertRaises(OverflowError):
1085+
curses.resize_term(35000, 1)
1086+
with self.assertRaises(OverflowError):
1087+
curses.resize_term(1, 35000)
1088+
# GH-120378: Overflow failure in resize_term() causes refresh to fail
1089+
tmp = curses.initscr()
1090+
tmp.erase()
1091+
10841092
@requires_curses_func('resizeterm')
10851093
def test_resizeterm(self):
10861094
curses.update_lines_cols()
@@ -1095,6 +1103,14 @@ def test_resizeterm(self):
10951103
self.assertEqual(curses.LINES, lines)
10961104
self.assertEqual(curses.COLS, cols)
10971105

1106+
with self.assertRaises(OverflowError):
1107+
curses.resizeterm(35000, 1)
1108+
with self.assertRaises(OverflowError):
1109+
curses.resizeterm(1, 35000)
1110+
# GH-120378: Overflow failure in resizeterm() causes refresh to fail
1111+
tmp = curses.initscr()
1112+
tmp.erase()
1113+
10981114
def test_ungetch(self):
10991115
curses.ungetch(b'A')
11001116
self.assertEqual(self.stdscr.getkey(), 'A')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash related to an integer overflow in :func:`curses.resizeterm`
2+
and :func:`curses.resize_term`.

Modules/_cursesmodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4071,9 +4071,9 @@ NoArgNoReturnFunctionBody(resetty)
40714071
/*[clinic input]
40724072
_curses.resizeterm
40734073
4074-
nlines: int
4074+
nlines: short
40754075
Height.
4076-
ncols: int
4076+
ncols: short
40774077
Width.
40784078
/
40794079
@@ -4084,8 +4084,8 @@ window dimensions (in particular the SIGWINCH handler).
40844084
[clinic start generated code]*/
40854085

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

@@ -4107,9 +4107,9 @@ _curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
41074107
/*[clinic input]
41084108
_curses.resize_term
41094109
4110-
nlines: int
4110+
nlines: short
41114111
Height.
4112-
ncols: int
4112+
ncols: short
41134113
Width.
41144114
/
41154115
@@ -4123,8 +4123,8 @@ without additional interaction with the application.
41234123
[clinic start generated code]*/
41244124

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

Modules/clinic/_cursesmodule.c.h

Lines changed: 79 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)