mirror of
https://github.com/junegunn/fzf.git
synced 2025-09-01 21:03:50 -07:00
Do not read more than 10K characters from /dev/tty
This might help with #1456 where fzf hangs consuming CPU resources.
This commit is contained in:
@@ -23,6 +23,7 @@ const (
|
|||||||
defaultEscDelay = 100
|
defaultEscDelay = 100
|
||||||
escPollInterval = 5
|
escPollInterval = 5
|
||||||
offsetPollTries = 10
|
offsetPollTries = 10
|
||||||
|
maxInputBuffer = 10 * 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
const consoleDevice string = "/dev/tty"
|
const consoleDevice string = "/dev/tty"
|
||||||
@@ -317,6 +318,13 @@ func (r *LightRenderer) getBytesInternal(buffer []byte, nonblock bool) []byte {
|
|||||||
}
|
}
|
||||||
buffer = append(buffer, byte(c))
|
buffer = append(buffer, byte(c))
|
||||||
pc = 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
|
return buffer
|
||||||
|
Reference in New Issue
Block a user