Skip to content

Add integer overflow guards to the curses chtype and color-pair packing path #152275

Description

@serhiy-storchaka

Bug report

Some curses methods silently truncate a color pair or attributes that do not fit in a chtype, turning a range error into a wrong-rendering bug instead of an exception:

  • curses.color_pair(n) masks n into the chtype's ~8-bit color field, so a pair ≥ 256 wraps to a lower pair and shows the wrong colors with no error (Ncurses Extended Color Pairs incorrectly display as copies of lower 256 color pairs #119138).
  • addch, addstr, addnstr, insch, insstr, insnstr, bkgd, bkgdset, echochar, hline, vline, box, border, attron, attroff, attrset and slk_attron/slk_attroff/slk_attrset take a raw long attr and narrow anything outside 0 .. 0xFFFFFFFF.

This is inconsistent with the rest of the module, which already raises rather than truncating: pair_converter (pair > INT_MAX/COLOR_PAIRS-1), component_converter (RGB outside 0..1000), attr_converter (gh-152219, value > (attr_t)-1) and curses_setcchar (pair beyond a short).

Linked PRs

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
No fields configured for issues without a type.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions