Skip to content

curses window.in_wstr() returns garbage when reading no characters #154781

Description

@fedonman

Bug description:

window.in_wstr(y, x, 0) reads uninitialized heap memory. winnwstr() only writes the
terminating null when it stored at least one character, but the buffer comes from
PyMem_New and the result is read with PyUnicode_FromWideChar(buf, -1), which scans for
that null (Modules/_cursesmodule.c:3853, :3869). The value differs on every run:

in_wstr(0, 0, 0)       -> ValueError: character U+e7180240 is not in range [U+0000; U+10ffff]
in_wstr(0, 0, 0)       -> ValueError: character U+20b80240 is not in range [U+0000; U+10ffff]

instr(0, 0, 0) and in_wchstr(0, 0, 0) correctly return b'' and
curses.complexstr([]).

gh-152503 fixed this for in_wch(), in_wchstr() and getbkgrnd(); in_wstr() was
missed, and unlike those it reproduces on stock ncursesw. It is new in 3.16 (gh-151757), so
no released version is affected.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions