Skip to content

Commit

Permalink
Ensure we never access out of range table dividers, fixes #2018 (#2026)
Browse files Browse the repository at this point in the history
ensure we never access out of range table dividers
  • Loading branch information
fpabl0 authored and andydotxyz committed Feb 26, 2021
1 parent fccfd1b commit 08bf087
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions widget/table.go
Expand Up @@ -330,7 +330,7 @@ func (t *tableRenderer) moveIndicators() {

divs := 0
i := minCol
for x := offX + visibleColWidths[i]; i < minCol+colDivs; x += visibleColWidths[i] + separatorThickness {
for x := offX + visibleColWidths[i]; i < minCol+colDivs && divs < len(t.dividers); x += visibleColWidths[i] + separatorThickness {
i++

t.dividers[divs].Move(fyne.NewPos(theme.Padding()+x-t.scroll.Offset.X, theme.Padding()))
Expand All @@ -341,7 +341,7 @@ func (t *tableRenderer) moveIndicators() {

i = 0
count := int(t.scroll.Offset.Y) % int(t.cellSize.Height+separatorThickness)
for y := theme.Padding() + t.scroll.Offset.Y - float32(count) - separatorThickness; y < t.scroll.Offset.Y+t.t.size.Height && i < rows-1; y += t.cellSize.Height + separatorThickness {
for y := theme.Padding() + t.scroll.Offset.Y - float32(count) - separatorThickness; y < t.scroll.Offset.Y+t.t.size.Height && i < rows-1 && divs < len(t.dividers); y += t.cellSize.Height + separatorThickness {
if y < theme.Padding()+t.scroll.Offset.Y {
continue
}
Expand Down
29 changes: 29 additions & 0 deletions widget/table_test.go
Expand Up @@ -303,3 +303,32 @@ func TestTable_ShowVisible(t *testing.T) {
cellRenderer.Refresh()
assert.Equal(t, 8, len(cellRenderer.Objects()))
}

func TestTable_SeparatorThicknessZero_NotPanics(t *testing.T) {
test.NewApp()
defer test.NewApp()

test.ApplyTheme(t, &separatorThicknessZeroTheme{test.Theme()})

table := NewTable(
func() (int, int) { return 500, 150 },
func() fyne.CanvasObject {
return NewLabel("placeholder")
},
func(TableCellID, fyne.CanvasObject) {})

assert.NotPanics(t, func() {
table.Resize(fyne.NewSize(400, 644))
})
}

type separatorThicknessZeroTheme struct {
fyne.Theme
}

func (t *separatorThicknessZeroTheme) Size(n fyne.ThemeSizeName) float32 {
if n == theme.SizeNameSeparatorThickness {
return 0
}
return t.Theme.Size(n)
}

0 comments on commit 08bf087

Please sign in to comment.