diff options
Diffstat (limited to 'cryptfs')
-rw-r--r-- | cryptfs/cryptfs_content.go | 16 | ||||
-rw-r--r-- | cryptfs/log.go | 1 |
2 files changed, 13 insertions, 4 deletions
diff --git a/cryptfs/cryptfs_content.go b/cryptfs/cryptfs_content.go index b9dd61f..374b4f4 100644 --- a/cryptfs/cryptfs_content.go +++ b/cryptfs/cryptfs_content.go @@ -97,12 +97,20 @@ func (be *CryptFS) SplitRange(offset uint64, length uint64) []intraBlock { // PlainSize - calculate plaintext size from ciphertext size func (be *CryptFS) PlainSize(size uint64) uint64 { + // Zero sized files stay zero-sized - if size > 0 { - overhead := be.cipherBS - be.plainBS - nBlocks := (size + be.cipherBS - 1) / be.cipherBS - size -= nBlocks * overhead + if size == 0 { + return 0 + } + + overhead := be.cipherBS - be.plainBS + nBlocks := (size + be.cipherBS - 1) / be.cipherBS + if nBlocks * overhead > size { + Warn.Printf("PlainSize: Negative size, returning 0 instead\n") + return 0 } + size -= nBlocks * overhead + return size } diff --git a/cryptfs/log.go b/cryptfs/log.go index 03d1e29..d40aa3f 100644 --- a/cryptfs/log.go +++ b/cryptfs/log.go @@ -26,4 +26,5 @@ func (l *logChannel) Enable() { var Debug = logChannel{false} +var Notice = logChannel{true} var Warn = logChannel{true} |