aboutsummaryrefslogtreecommitdiff
path: root/cryptfs
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-11-15 14:15:21 +0100
committerJakob Unterwurzacher2015-11-15 14:15:21 +0100
commit296bdf3af21a8964dcb884ff41ea7556cc811e9a (patch)
tree0ce449c4c27b6eb52746aad4853b5c76661c9bfe /cryptfs
parent09499be6e9bffe3bd24f017b15736125d72c450c (diff)
CipherSizeToPlainSize: Handle illegal states
A file never gets a cipherSize <= HEADER_LEN in normal operation. However, this can happen if header write it interrupted or the underlying filesystem does not support fallocate. Noticed while trying to store a CIPHERDIR in another gocryptfs mount (gocryptfs does not support fallocate)
Diffstat (limited to 'cryptfs')
-rw-r--r--cryptfs/address_translation.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/cryptfs/address_translation.go b/cryptfs/address_translation.go
index dfc6ef9..147040c 100644
--- a/cryptfs/address_translation.go
+++ b/cryptfs/address_translation.go
@@ -30,6 +30,16 @@ func (be *CryptFS) CipherSizeToPlainSize(cipherSize uint64) uint64 {
return 0
}
+ if cipherSize == HEADER_LEN {
+ Warn.Printf("cipherSize %d == header size: interrupted write?\n", cipherSize)
+ return 0
+ }
+
+ if cipherSize < HEADER_LEN {
+ Warn.Printf("cipherSize %d < header size: corrupt file\n", cipherSize)
+ return 0
+ }
+
// Block number at last byte
blockNo := be.CipherOffToBlockNo(cipherSize - 1)
blockCount := blockNo + 1