diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2020-03-07 11:20:44 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2020-03-07 11:20:44 +0900 |
commit | ba82f0bef99299a2c8a7a9cacde55c28568c9c3b (patch) | |
tree | 2ab6b1d3b4a3d7b407dbf89026cffbec3daad53e | |
parent | d9c6a0305b8c7f83a21fa583ae662660b940b1b6 (diff) |
Do not read more than 10K characters from /dev/tty
This might help with #1456 where fzf hangs consuming CPU resources.
-rw-r--r-- | src/tui/light.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/tui/light.go b/src/tui/light.go index fbc76f59..d8de4b66 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -23,6 +23,7 @@ const ( defaultEscDelay = 100 escPollInterval = 5 offsetPollTries = 10 + maxInputBuffer = 10 * 1024 ) const consoleDevice string = "/dev/tty" @@ -317,6 +318,13 @@ func (r *LightRenderer) getBytesInternal(buffer []byte, nonblock bool) []byte { } buffer = append(buffer, byte(c)) pc = c + + // This should never happen under normal conditions, + // so terminate fzf immediately. + if len(buffer) > maxInputBuffer { + r.Close() + panic(fmt.Sprintf("Input buffer overflow (%d): %v", len(buffer), buffer)) + } } return buffer |