diff options
author | Jakob Unterwurzacher | 2015-09-16 19:32:37 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2015-09-16 19:32:37 +0200 |
commit | 0af3cfcac0d6e5515ac37ee02712178218205a18 (patch) | |
tree | b37c67f573b9164a05ddd821449dc0353893e2f8 /cryptfs | |
parent | 3a2610a141b3afb96050b8dc4f7262939d563133 (diff) |
Fix symlink size reporting
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} |