Skip to content

Commit

Permalink
fix(indexer): crash on directory traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
waynezhang committed Feb 28, 2024
1 parent 4410bcd commit 45de818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func buildImageSets(folder string, ascending bool, option config.ExtractOption)
mutext := &sync.Mutex{}

_ = filepath.WalkDir(folder, func(path string, info os.DirEntry, err error) error {
if err != nil {
log.Warn().Msgf("Failed to extract info from %s (%v)", path, err)
return nil
}
if info.IsDir() || !images.IsPhotoSupported(path) {
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions internal/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package indexer

import (
"html/template"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -88,6 +89,13 @@ func TestBuildImageSets(t *testing.T) {
})
}

func TestInvalidBuildImageSets(t *testing.T) {
tmp, _ := os.MkdirTemp("", "foto-test")
path := filepath.Join(tmp, "folder-not-exist")
// no crash expected
_ = buildImageSets(path, true, defaultOption)
}

func TestBuildImageSet(t *testing.T) {
set, _ := buildImageSet(testdata.Testfile, defaultOption)
assert.Equal(t, filepath.Base(testdata.Testfile), set.FileName)
Expand Down

0 comments on commit 45de818

Please sign in to comment.