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)
This commit is contained in:
parent
09499be6e9
commit
296bdf3af2
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user