conentenc: handle zero-sized files in PlainSizeToCipherSize

Previously caused an integer underflow.
This commit is contained in:
Jakob Unterwurzacher 2016-08-29 21:55:10 +02:00
parent 9237b4f53e
commit 1d62086742

View File

@ -28,8 +28,7 @@ func (be *ContentEnc) BlockNoToPlainOff(blockNo uint64) uint64 {
// PlainSize - calculate plaintext size from ciphertext size
func (be *ContentEnc) CipherSizeToPlainSize(cipherSize uint64) uint64 {
// Zero sized files stay zero-sized
// Zero-sized files stay zero-sized
if cipherSize == 0 {
return 0
}
@ -55,6 +54,10 @@ func (be *ContentEnc) CipherSizeToPlainSize(cipherSize uint64) uint64 {
// CipherSize - calculate ciphertext size from plaintext size
func (be *ContentEnc) PlainSizeToCipherSize(plainSize uint64) uint64 {
// Zero-sized files stay zero-sized
if plainSize == 0 {
return 0
}
// Block number at last byte
blockNo := be.PlainOffToBlockNo(plainSize - 1)