aboutsummaryrefslogtreecommitdiff
path: root/internal/contentenc/offsets.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-03-06 23:50:17 +0100
committerJakob Unterwurzacher2017-03-07 20:56:50 +0100
commit2f953fdb95f44078895fec9bc4d542cd371126be (patch)
treeda1a2cf8fa8f438f27193ce09b8ef2017a54bbb8 /internal/contentenc/offsets.go
parentefc88346bec52675d5243f988aa3386d617ee1c4 (diff)
contentenc: catch integer underflow in file size calculation
If you truncate a ciphertext file to 19 bytes, you could get the impression that the plaintext is 18446744073709551585 bytes long, as reported by "ls -l". Fix it by clamping the value to zero.
Diffstat (limited to 'internal/contentenc/offsets.go')
-rw-r--r--internal/contentenc/offsets.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/contentenc/offsets.go b/internal/contentenc/offsets.go
index 97d7116..5ad0da4 100644
--- a/internal/contentenc/offsets.go
+++ b/internal/contentenc/offsets.go
@@ -54,6 +54,11 @@ func (be *ContentEnc) CipherSizeToPlainSize(cipherSize uint64) uint64 {
overhead := be.BlockOverhead()*blockCount + HeaderLen
+ if overhead > cipherSize {
+ tlog.Warn.Printf("cipherSize %d < overhead %d: corrupt file\n", cipherSize, overhead)
+ return 0
+ }
+
return cipherSize - overhead
}