Skip to content

bytes_to_read() raises SystemError: buffer overflow on Python 3.14 (FIONREAD undersized buffer) #1070

@RemiDesgrange

Description

@RemiDesgrange

Hi,

Same root cause as #1038 (fixed for _pty_size) but in terminals.bytes_to_read(), which was not touched by that fix.

On Python 3.14, fcntl.ioctl rejects undersized mutable buffers (cpython#144206). bytes_to_read passes a 2-byte buffer to FIONREAD, which writes a C int (4 bytes):

fionread = fcntl.ioctl(input_, termios.FIONREAD, b"  ")
return int(struct.unpack("h", fionread)[0])

which worked by accident on ≤3.13 thanks to the 1024-byte static copy buffer

Repro: any Connection.run() from a TTY-attached process on 3.14 crashes the handle_stdin thread

Do you want me to make a PR a fix with something like fionread = fcntl.ioctl(input_, termios.FIONREAD, b"\x00\x00\x00\x00") in https://github.com/pyinvoke/invoke/blob/main/invoke/terminals.py#L246-L247

Thx.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions