diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 25ce354e0..f22302ad6 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -31,7 +31,7 @@ }, { "ImportPath": "github.com/syncthing/protocol", - "Rev": "442e93d3fc7728d7560c8d039a4199a77879b9f6" + "Rev": "4395711d26c61e7e422a8c8da43dda164f1820f4" }, { "ImportPath": "github.com/syndtr/goleveldb/leveldb", diff --git a/Godeps/_workspace/src/github.com/syncthing/protocol/protocol.go b/Godeps/_workspace/src/github.com/syncthing/protocol/protocol.go index eeaf0f46b..7f1dd4598 100644 --- a/Godeps/_workspace/src/github.com/syncthing/protocol/protocol.go +++ b/Godeps/_workspace/src/github.com/syncthing/protocol/protocol.go @@ -43,6 +43,8 @@ const ( FlagSymlink = 1 << 16 FlagSymlinkMissingTarget = 1 << 17 + FlagsAll = (1 << iota) - 1 + SymlinkTypeMask = FlagDirectory | FlagSymlinkMissingTarget ) diff --git a/internal/model/model.go b/internal/model/model.go index daddd1d0b..0c26d9dd4 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -485,7 +485,13 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F for i := 0; i < len(fs); { lamport.Default.Tick(fs[i].Version) - if symlinkInvalid(fs[i].IsSymlink()) { + if fs[i].Flags&^protocol.FlagsAll != 0 { + if debug { + l.Debugln("dropping update for file with unknown bits set", fs[i]) + } + fs[i] = fs[len(fs)-1] + fs = fs[:len(fs)-1] + } else if symlinkInvalid(fs[i].IsSymlink()) { if debug { l.Debugln("dropping update for unsupported symlink", fs[i]) } @@ -528,7 +534,13 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot for i := 0; i < len(fs); { lamport.Default.Tick(fs[i].Version) - if symlinkInvalid(fs[i].IsSymlink()) { + if fs[i].Flags&^protocol.FlagsAll != 0 { + if debug { + l.Debugln("dropping update for file with unknown bits set", fs[i]) + } + fs[i] = fs[len(fs)-1] + fs = fs[:len(fs)-1] + } else if symlinkInvalid(fs[i].IsSymlink()) { if debug { l.Debugln("dropping update for unsupported symlink", fs[i]) } diff --git a/internal/model/model_test.go b/internal/model/model_test.go index 2e8285832..1e019a1d1 100644 --- a/internal/model/model_test.go +++ b/internal/model/model_test.go @@ -525,3 +525,58 @@ func TestIgnores(t *testing.T) { t.Errorf("Expected no ignores, got: %v", ignores) } } + +func TestRefuseUnknownBits(t *testing.T) { + fcfg := config.FolderConfiguration{ + ID: "default", + Path: "testdata", + Devices: []config.FolderDeviceConfiguration{ + { + DeviceID: device1, + }, + }, + } + cfg := config.Configuration{ + Folders: []config.FolderConfiguration{fcfg}, + Devices: []config.DeviceConfiguration{ + { + DeviceID: device1, + }, + }, + } + + db, _ := leveldb.Open(storage.NewMemStorage(), nil) + m := NewModel(config.Wrap("/tmp/test", cfg), "device", "syncthing", "dev", db) + m.AddFolder(fcfg) + + m.ScanFolder("default") + m.Index(device1, "default", []protocol.FileInfo{ + { + Name: "invalid1", + Flags: protocol.FlagsAll + 1, + }, + { + Name: "invalid2", + Flags: protocol.FlagsAll + 2, + }, + { + Name: "invalid3", + Flags: 1 << 31, + }, + { + Name: "valid", + Flags: protocol.FlagsAll, + }, + }) + + for _, name := range []string{"invalid1", "invalid2", "invalid3"} { + f, ok := m.CurrentGlobalFile("default", name) + if ok || f.Name == name { + t.Error("Invalid file found or name match") + } + } + f, ok := m.CurrentGlobalFile("default", "valid") + if !ok || f.Name != "valid" { + t.Error("Valid file not found or name mismatch", ok, f) + } +}