Check pathlength before reading metadata (#13080)

fixes bug where the server returns 503 instead of 400 if 
objectName is longer than 255 characters

Fixes regression introduced in #12942
This commit is contained in:
Poorna Krishnamoorthy 2021-08-26 19:23:12 -04:00 committed by GitHub
parent c11a2ac396
commit 27f895cf2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -397,6 +397,10 @@ func (s *xlStorage) Healing() *healingTracker {
} }
func (s *xlStorage) readMetadata(itemPath string) ([]byte, error) { func (s *xlStorage) readMetadata(itemPath string) ([]byte, error) {
if err := checkPathLength(itemPath); err != nil {
return nil, err
}
f, err := OpenFile(itemPath, readMode, 0) f, err := OpenFile(itemPath, readMode, 0)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1818,3 +1818,23 @@ func TestXLStorageVerifyFile(t *testing.T) {
t.Fatal("expected to fail bitrot check") 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)
}
}