diff options
author | Jakob Unterwurzacher | 2019-02-17 17:05:05 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2019-02-17 17:05:05 +0100 |
commit | 19cb6d046aac92f44722c17ba9a371b08ca0be6a (patch) | |
tree | c7134052a935c75ab834786a59df9529aa8495f3 /tests | |
parent | 26286a5f8cbd11557bc6e733741fbd3980f6d050 (diff) |
nametransform: reject names longer than 255 chars
Looks like we allowed creating longer names by accident.
Fix that, and add a test that verifies it.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/matrix/matrix_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index be47990..33d2ab2 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -377,6 +377,57 @@ func TestRename(t *testing.T) { test_helpers.TestRename(t, test_helpers.DefaultPlainDir) } +// Test that names of all lengths work +func TestNameLengths(t *testing.T) { + f, err := os.Open(test_helpers.DefaultPlainDir) + if err != nil { + t.Fatal(err) + } + entries, err := f.Readdirnames(0) + if err != nil { + t.Fatal(err) + } + f.Close() + cnt1 := len(entries) + + wd := test_helpers.DefaultPlainDir + "/" + name := "x" + for len(name) < 2000 { + f, err := os.Create(wd + name + "x") + if err != nil { + break + } + name = name + "x" + f.Close() + f, err = os.Open(test_helpers.DefaultPlainDir) + if err != nil { + t.Fatal(err) + } + // In v1.7-rc2, we had a bug that allowed creation of too-long names. + // This threw errors in like this in READDIR: + // + // OpenDir ".": invalid entry "gocryptfs.longname.wrE-izsR9ciEkP7JSCFDrk_d_Nj4mQo1dGY6hjuixAU=": + // Could not read .name: ReadLongName: size=345 > limit=344 + // + entries, err = f.Readdirnames(0) + if err != nil { + t.Fatal(err) + } + f.Close() + cnt2 := len(entries) + if cnt2 != cnt1+1 { + t.Fatalf("len=%d: expected %d dir entries, have %d: %v", len(name), cnt1+1, cnt2, entries) + } + err = syscall.Unlink(wd + name) + if err != nil { + t.Fatal(err) + } + } + if len(name) != 255 { + t.Errorf("maxlen=%d", len(name)) + } +} + func TestLongNames(t *testing.T) { fi, err := ioutil.ReadDir(test_helpers.DefaultCipherDir) if err != nil { |