aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/reverse_longnames.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-10-01 13:50:25 +0200
committerJakob Unterwurzacher2017-10-01 13:50:25 +0200
commit4da245c69d7994efec75e1deaef56a03020d39db (patch)
treef9d429bd039774f4ecd06afb18844ece5a4d5bb4 /internal/fusefrontend_reverse/reverse_longnames.go
parent0072a96f20c99bf386d8e3f63741def5a3945018 (diff)
fusefrontend_reverse: fix 176-byte names
A file with a name of exactly 176 bytes length caused this error: ls: cannot access ./tmp/dsg/sXSGJLTuZuW1FarwIkJs0w/b6mGjdxIRpaeanTo0rbh0A/QjMRrQZC_4WLhmHI1UOBcA/gocryptfs.longname.QV-UipdDXeUVdl05WruoEzBNPrQCfpu6OzJL0_QnDKY: No such file or directory ls: cannot access ./tmp/dsg/sXSGJLTuZuW1FarwIkJs0w/b6mGjdxIRpaeanTo0rbh0A/QjMRrQZC_4WLhmHI1UOBcA/gocryptfs.longname.QV-UipdDXeUVdl05WruoEzBNPrQCfpu6OzJL0_QnDKY.name: No such file or directory -????????? ? ? ? ? ? gocryptfs.longname.QV-UipdDXeUVdl05WruoEzBNPrQCfpu6OzJL0_QnDKY -????????? ? ? ? ? ? gocryptfs.longname.QV-UipdDXeUVdl05WruoEzBNPrQCfpu6OzJL0_QnDKY.name Root cause was a wrong shortNameMax constant that failed to account for the obligatory padding byte. Fix the constant and also expand the TestLongnameStat test case to test ALL file name lengths from 1-255 bytes. Fixes https://github.com/rfjakob/gocryptfs/issues/143 .
Diffstat (limited to 'internal/fusefrontend_reverse/reverse_longnames.go')
-rw-r--r--internal/fusefrontend_reverse/reverse_longnames.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/fusefrontend_reverse/reverse_longnames.go b/internal/fusefrontend_reverse/reverse_longnames.go
index ec164f1..3bfe3af 100644
--- a/internal/fusefrontend_reverse/reverse_longnames.go
+++ b/internal/fusefrontend_reverse/reverse_longnames.go
@@ -17,7 +17,14 @@ import (
)
const (
- shortNameMax = 176
+ // File names are padded to 16-byte multiples, encrypted and
+ // base64-encoded. We can encode at most 176 bytes to stay below the 255
+ // bytes limit:
+ // * base64(176 bytes) = 235 bytes
+ // * base64(192 bytes) = 256 bytes (over 255!)
+ // But the PKCS#7 padding is at least one byte. This means we can only use
+ // 175 bytes for the file name.
+ shortNameMax = 175
)
var longnameParentCache map[string]string
@@ -57,6 +64,7 @@ func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname stri
}
dirEntries, err := dirfd.Readdirnames(-1)
if err != nil {
+ tlog.Warn.Printf("findLongnameParent: Readdirnames failed: %v\n", err)
return "", err
}
longnameCacheLock.Lock()
@@ -78,7 +86,6 @@ func (rfs *ReverseFS) findLongnameParent(dir string, dirIV []byte, longname stri
if hit == "" {
return "", syscall.ENOENT
}
-
return hit, nil
}