aboutsummaryrefslogtreecommitdiff
path: root/cryptfs/cryptfs_content.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-16 19:32:37 +0200
committerJakob Unterwurzacher2015-09-16 19:32:37 +0200
commit0af3cfcac0d6e5515ac37ee02712178218205a18 (patch)
treeb37c67f573b9164a05ddd821449dc0353893e2f8 /cryptfs/cryptfs_content.go
parent3a2610a141b3afb96050b8dc4f7262939d563133 (diff)
Fix symlink size reporting
Diffstat (limited to 'cryptfs/cryptfs_content.go')
-rw-r--r--cryptfs/cryptfs_content.go16
1 files changed, 12 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
}