fix: ingnore implausible terminal resize reports (#1887)
Signed-off-by: drew <me@andrinoff.com>
This commit is contained in:
parent
f9df43c4f2
commit
9c6c325f83
3 changed files with 41 additions and 0 deletions
15
screen.go
15
screen.go
|
|
@ -64,3 +64,18 @@ type ModeReportMsg struct {
|
|||
// Value is the mode value.
|
||||
Value ansi.ModeSetting
|
||||
}
|
||||
|
||||
const (
|
||||
maxWindowDimension = 4096
|
||||
maxWindowCells = 1 << 20
|
||||
)
|
||||
|
||||
func isPlausibleWindowSize(width, height int) bool {
|
||||
if width < 0 || height < 0 {
|
||||
return false
|
||||
}
|
||||
if width > maxWindowDimension || height > maxWindowDimension {
|
||||
return false
|
||||
}
|
||||
return width*height <= maxWindowCells
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,3 +205,25 @@ func TestClearMsg(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsPlausibleWindowSize(t *testing.T) {
|
||||
tests := []struct {
|
||||
w, h int
|
||||
want bool
|
||||
}{
|
||||
{80, 24, true},
|
||||
{0, 0, true},
|
||||
{500, 200, true},
|
||||
{-1, 24, false},
|
||||
{80, -1, false},
|
||||
{5000, 1, false},
|
||||
{23000, 23000, false},
|
||||
{29000, 29000, false},
|
||||
{2000, 2000, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := isPlausibleWindowSize(tt.w, tt.h); got != tt.want {
|
||||
t.Errorf("isPlausibleWindowSize(%d, %d) = %v, want %v", tt.w, tt.h, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
tea.go
4
tea.go
|
|
@ -776,6 +776,10 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
|
|||
case msg := <-p.msgs:
|
||||
msg = p.translateInputEvent(msg)
|
||||
|
||||
if size, ok := msg.(WindowSizeMsg); ok && !isPlausibleWindowSize(size.Width, size.Height) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Filter messages.
|
||||
if p.filter != nil {
|
||||
msg = p.filter(model, msg)
|
||||
|
|
|
|||
Loading…
Reference in a new issue