diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index 0b72f2763..6e5391419 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -397,6 +397,10 @@ func (s *xlStorage) Healing() *healingTracker { } func (s *xlStorage) readMetadata(itemPath string) ([]byte, error) { + if err := checkPathLength(itemPath); err != nil { + return nil, err + } + f, err := OpenFile(itemPath, readMode, 0) if err != nil { return nil, err diff --git a/cmd/xl-storage_test.go b/cmd/xl-storage_test.go index 8bdb1880b..b14c3add2 100644 --- a/cmd/xl-storage_test.go +++ b/cmd/xl-storage_test.go @@ -1818,3 +1818,23 @@ func TestXLStorageVerifyFile(t *testing.T) { t.Fatal("expected to fail bitrot check") } } + +// TestXLStorageReadMetadata tests readMetadata +func TestXLStorageReadMetadata(t *testing.T) { + volume, object := "test-vol", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + tmpDir, err := ioutil.TempDir("", "") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) + + disk, err := newLocalXLStorage(tmpDir) + if err != nil { + t.Fatal(err) + } + + disk.MakeVol(context.Background(), volume) + if _, err := disk.readMetadata(pathJoin(tmpDir, volume, object)); err != errFileNameTooLong { + t.Fatalf("Unexpected error from readMetadata - expect %v: got %v", errFileNameTooLong, err) + } +}