From 0af3cfcac0d6e5515ac37ee02712178218205a18 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 16 Sep 2015 19:32:37 +0200 Subject: Fix symlink size reporting --- cryptfs/cryptfs_content.go | 16 ++++++++++++---- cryptfs/log.go | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'cryptfs') 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} -- cgit v1.2.3