diff options
author | kylosus <33132401+kylosus@users.noreply.github.com> | 2024-01-28 21:50:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-28 19:50:26 +0100 |
commit | 302b352d78692bed09ca2b050d0abd9fc3932e74 (patch) | |
tree | ae1ef5a40fbd032df741a239f37c73b41350fed8 | |
parent | 45beb28fa5b051d14a10f102a05ec46d36ecaa75 (diff) |
lib/fs: Add invalid UTF-8 guards to watcher (fixes #9369) (#9372)
Add invalid UTF-8 guards to fix #9369. Probably not a permanent fix, but
putting it up here in case someone else encounters the same panic.
-rw-r--r-- | lib/fs/basicfs_watch.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/fs/basicfs_watch.go b/lib/fs/basicfs_watch.go index ca3f306d3f..c65529cc50 100644 --- a/lib/fs/basicfs_watch.go +++ b/lib/fs/basicfs_watch.go @@ -14,6 +14,7 @@ package fs import ( "context" "errors" + "unicode/utf8" "github.com/syncthing/notify" ) @@ -38,6 +39,10 @@ func (f *BasicFilesystem) Watch(name string, ignore Matcher, ctx context.Context } absShouldIgnore := func(absPath string) bool { + if !utf8.ValidString(absPath) { + return true + } + rel, err := f.unrootedChecked(absPath, roots) if err != nil { return true @@ -78,7 +83,14 @@ func (f *BasicFilesystem) watchLoop(ctx context.Context, name string, roots []st select { case ev := <-backendChan: - relPath, err := f.unrootedChecked(ev.Path(), roots) + evPath := ev.Path() + + if !utf8.ValidString(evPath) { + l.Debugln(f.Type(), f.URI(), "Watch: Ignoring invalid UTF-8") + continue + } + + relPath, err := f.unrootedChecked(evPath, roots) if err != nil { select { case errChan <- err: |