Skip to content

Commit e1e5d11

Browse files
committed
fix: Buffer overflow in bytes_to_read
Fix buffer overflow error in invoke/terminals.py::bytes_to_read by providing correctly sized int.
1 parent ba193d1 commit e1e5d11

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

invoke/terminals.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from contextlib import contextmanager
1111
from typing import Generator, IO, Optional, Tuple
1212
import os
13+
import struct
1314
import select
1415
import sys
1516

@@ -243,6 +244,7 @@ def bytes_to_read(input_: IO) -> int:
243244
# it's not a tty but has a fileno, or vice versa; neither is typically
244245
# going to work re: ioctl().
245246
if not WINDOWS and isatty(input_) and has_fileno(input_):
246-
fionread = fcntl.ioctl(input_, termios.FIONREAD, b" ")
247-
return int(struct.unpack("h", fionread)[0])
247+
arg = bytes(bytearray(struct.calcsize("i")))
248+
fionread = fcntl.ioctl(input_, termios.FIONREAD, arg)
249+
return int(struct.unpack("i", fionread)[0])
248250
return 1

0 commit comments

Comments
 (0)